mkdir command in Linux allows the user to create directories (also referred to as folders in some operating systems). This command can create multiple directories at once as well as set the permissions for the directories. It is important to note that the user executing this command must have enough permission to create a directory in the parent directory, or he/she may receive a ‘permission denied’ error.
Syntax:
mkdir [options...] [directories ...]
Options available in mkdir
1) –help:
It displays help-related information and exits.
Syntax:
mkdir --help

mkdir –help
2) –version:
It displays the version number, some information regarding the license and exits.
Syntax:
mkdir --version

mkdir –version
3) -v or –verbose:
It displays a message for every directory created.
Syntax:
mkdir -v [directories]

mkdir -v [directories]
Here we have used `ls` command to display all files and directories.
As we can see we have created tow directory with “names = jayeshghg_1 and jayeshgfg_2”, replace these names with the directory name you want.
4) -p:
A flag which enables the command to create parent directories as necessary. If the directories exist, no error is specified.
Syntax:
mkdir -p [directories]
Suppose you execute the following command –
mkdir -p first/second/third
If the first and second directories do not exist, due to the -p option, mkdir will create these directories for us. If we do not specify the -p option, and request the creation of directories, where parent directory doesn’t exist, we will get the following output –

mkdir first/second/third
If we specify the -p option, the directories will be created, and no error will be reported. Following is the output of one such execution. We’ve also provided the -v option, so that we can see it in action.

-p option
5) -m:
This option is used to set the file modes, i.e. permissions, etc. for the created directories. The syntax of the mode is the same as the chmod command.
Syntax:
mkdir -m a=rwx [directories]
The above syntax specifies that the directories created give access to all the users to read from, write to and execute the contents of the created directories. You can use ‘a=r’ to only allow all the users to read from the directories and so on.
![mkdir -m a=rwx [directories]](https://media.geeksforgeeks.org/wp-content/uploads/20230427163917/100.webp)
mkdir -m a=rwx [directories]
Examples to demonstrate the usage of the `mkdir` command
1) How to create a directory using `mkdir` command?
Syntax:
mkdir [directorie_name]
For Example:
If we want to create a directory name “jayesh_gfg”.
Syntax:
mkdir jayesh_gfg

mkdir jayesh_gfg
Here we have used `ls` command to display all files and directories.
2) How to create a directory with verbose output using `mkdir` command?
Syntax:
mkdir -v [directory_name]
For Example:
If we want to create a directory name “geeksforgeeks” and see verbose at same time. You can enter your directory_name.
Syntax:
mkdir -v geeksforgeeks

mkdir -v geeksforgeeks
Here we have used `ls` command to display all files and directories.
3) How to create multiple directories using `mkdir` command?
Syntax:
mkdir [directorie_name_1] [directorie_name_1] [directorie_name_1] .......
For Example:
If we want to create a directory name “jayesh_gfg_1, jayesh_gfg_2, jayesh_gfg_3”.
Syntax:
mkdir jayesh_gfg_1 jayesh_gfg_2 jayesh_gfg_3

mkdir jayesh_gfg_1 jayesh_gfg_2 jayesh_gfg_3
Here we have used `ls` command to display all files and directories.
4) How to resolve permission denied error in `mkdir` command?
If you encounter a “permission denied” error while creating a directory, you may not have permission to create directories in that location. To resolve this you can give root access to the user by using “sudo” command.
For Example:
If we want to create a directory name “geeksforgeek” with “sudo” permission. you can replace “geeksforgeek” directory_name with your directory_name. While using this command it may ask you to enter the password of root.
Syntax:
sudo mkdir geeksforgeek

sudo mkdir geeksforgeek
Conclusion
If you’re a Linux user, you’ll find that the mkdir command is incredibly useful for creating directories or folders quickly and efficiently. It provides a range of options that can help you customize the way you create directories, such as verbose output, setting permissions, and creating multiple directories simultaneously. However, it’s worth noting that you’ll need the appropriate permissions to create directories in specific locations, or else you may run into “permission denied” errors. Learning how to use the mkdir command effectively can significantly improve your ability to organize files and directories and boost your productivity on Linux.