This article serves as a comprehensive guide to the Linux ‘mkdir’ command, designed for beginners. It covers everything from the history of the command to its usage, parameters, common use cases, and some of its less known features. By the end of the guide, the reader should have a thorough understanding of ‘mkdir’ and be able to use it effectively in their work.
Instructions
This guide provides an in-depth introduction to the Linux ‘mkdir’ command. It covers the history of the command, when and why to use it, how to use it, and the commonly used and other supported parameters. We’ll also walk through the most common use cases and explore some of the command’s more advanced features and techniques.
History
The ‘mkdir’ command, short for “make directory,” has been a part of UNIX and UNIX-like systems, including Linux, since their earliest versions. It’s a fundamental tool in these operating systems for creating new directories.
When and why to use it
The ‘mkdir’ command is used when you need to create a new directory. It’s an essential command for any system user or administrator for organizing files and directories.
How to use it
The basic usage of the ‘mkdir’ command is straightforward. You simply type ‘mkdir’ followed by the name of the directory you want to create.
mkdir new_directory
The commonly used parameters
-p
This parameter is used when you want to create a directory and its parents if they do not already exist.
mkdir -p dir/subdir/subsubdir
-m
This parameter is used to set the file mode (permissions) for the new directory.
mkdir -m 755 new_directory
Other supported parameters
-v
: Verbose mode, provides additional details about the command's execution-Z
: Set the SELinux security context of the new directory to the system default
Most common use cases
The most common use case for ‘mkdir’ is creating a new directory. It is also frequently used with the -p
option to create nested directories in a single command.
mkdir new_project
mkdir -p projects/new_project/src
The tricky skills
One less commonly known feature of ‘mkdir’ is its ability to create multiple directories at once. By supplying multiple arguments, you can create several directories with one command.
mkdir dir1 dir2 dir3
What needs to be noted
It’s important to note that ‘mkdir’ will not overwrite existing directories. If you attempt to create a directory that already exists, ‘mkdir’ will return an error.
Conclusion
The ‘mkdir’ command is a fundamental yet powerful tool in Linux. By understanding its parameters and usage, you can make your work in the Linux command line more efficient.