Using the mkdir command
In this tutorial, you will learn how to use the mkdir command to create a new directory in Linux. You will also learn about the various options available with the mkdir command, such as the -p and -v options, which allow you to create a directory and any missing parent directories, and display a message for each directory created, respectively. You will also learn how to combine multiple options to customise the behaviour of the mkdir command.
The mkdir
command is a basic Linux command that is used to create a new directory. It is an essential tool for organising files and directories into logical structures.
Here is a tutorial on using the mkdir
command:
Basic Usage
To create a new directory, simply type mkdir
followed by the name of the directory you want to create, and press enter:
$ mkdir directory_name
For example, to create a new directory called documents
, you would use the following command:
$ mkdir documents
This will create a new directory with the specified name in the current working directory.
Creating a Directory in a Different Location
If you want to create the directory in a different location, you can specify the path to the parent directory as an argument, like this:
$ mkdir /path/to/parent/directory/directory_name
For example, to create the documents
directory within the /home/user
directory, you would use the following command:
$ mkdir /home/user/documents
Options
The mkdir
command also has several options that can be used to customize its behavior. Some of the most useful options include:
-p
: This option allows you to create a directory and any missing parent directories in the specified path. This is useful if you want to create a directory within a hierarchy of directories that do not yet exist.-v
: This option displays a message for each directory that is created. This is useful for debugging or seeing the progress of the command.
To use these options, simply include them as arguments to the mkdir
command, like this:
$ mkdir -p /path/to/parent/directory/directory_name
$ mkdir -v directory_name
Combining Options
You can also combine multiple options by grouping them together after a single dash, like this:
$ mkdir -pv directory_name
This will create the directory_name
directory and display a message for each directory that is created.
I hope this tutorial on the mkdir
command has been helpful!