In Linux, mkdir
stands for “make directory”, and it is a commonly used command that allows you to create new directories or folders. mkdir command in Linux is used in the command-line interface (CLI) of the Linux operating system.
The mkdir
the command is very useful when you need to organize your files and data into separate directories. With the mkdir
command, you can easily create new directories in any location of your choice.
In this article, we will discuss how to use the mkdir
command in Linux to create new directories.
Basic Syntax
The basic syntax of the mkdir
command is as follows:
mkdir directory_name
This command will create a new directory with the name directory_name
in the current working directory. The current working directory is the directory that you are currently located in.
For example, if your current working directory is /home/user
, and you run the following command:
mkdir new_directory
This will create a new directory named new_directory
inside the /home/user
directory.
Creating Directories with a Path
You can also create a new directory with a specific path using the mkdir
command. A path is a sequence of directories separated by a forward slash /
.
For example, if you want to create a new directory named new_directory
inside the /home/user/documents
directory, you can run the following command:
mkdir /home/user/documents/new_directory
This command will create a new directory named new_directory
inside the documents
directory, which is located in the user
directory of the home
directory.
Creating Multiple Directories
You can create multiple directories at once by specifying multiple directory names separated by a space.
For example, if you want to create three new directories named directory1
, directory2
, and directory3
in the current working directory, you can run the following command:
mkdir directory1 directory2 directory3
This will create three new directories in the current working directory.
Creating Parent Directories
If you want to create a new directory and its parent directories if they do not exist, you can use the -p
option with the mkdir
command.
For example, if you want to create a new directory named subdirectory
inside the /home/user/documents/new_directory
directory, and create the new_directory
and documents
directories if they do not already exist, you can run the following command:
mkdir -p /home/user/documents/new_directory/subdirectory
This will create a new directory named subdirectory
inside the new_directory
directory, and create the new_directory
and documents
directories if they do not already exist.
Conclusion
The mkdir command in Linux is a very useful command that allows you to create new directories or folders. With the mkdir
command, you can easily organize your files and data into separate directories.
In this article, we discussed how to use the mkdir
command in Linux to create new directories. We covered the basic syntax of the mkdir
command, creating directories with a path, creating multiple directories, and creating parent directories, see the man page for the cat command.
I hope this article has been helpful in understanding the mkdir
command in Linux. Thank you for reading!
If you have any questions please leave them in the comments below