What is the mkdir command in Linux?

In Linux or Unix-like Operating system, we use the mkdir command to create a new empty directory. The directory is generally known as a folder in Windows or Mac computers. The mkdir stands for make directory.

If you like to watch the mkdir command video then you can watch the video.

mkdir command in Linux | Watch mkdir command in the video.

How to get help for the mkdir command

I always suggest reading the manual page and help. So, it will give you an in-depth introduction to the command.

To get the manual page type the below command,

man mkdir

But, to get the only command options, you can type the below command.

mkdir --help

Syntax of the mkdir command

Now you know how to get help with the mkdir command. So, let’s talk about mkdir syntax. The syntax of the mkdir command is as below,

Syntax: mkdir [options] Directory

So let’s use the mkdir command in Linux.

Creating a single directory with mkdir command

Now we have a lot of information about mkdir; So, this is the time to play with the mkdir command. For example, I am going to create a new directory with the name amit in the current directory.

mkdir amit

Below you can see in the picture I have created a directory with the name amit and I have listed the directory with the ls -l command.

mkdir command
Creating a directory with the name amit using the mkdir command

Creating multiple directories at once with mkdir command

You can create multiple directories at a time. Now you have to put a space between the directories’ names. You can see in the example below.

mkdir david ram bhupi aman home songs
mkdir command in Linux
Creating multiple directories once using the mkdir command.

Creating a parent directory with -p argument

I want to tell you one argument which is very useful if you are creating a new directory inside a new directory. If you create without the argument for the first-time parent directory and then one more directory inside it, you will get an error message.

So, Let me take an example, I want to create a directory aman inside the directory bhupi. Here I have to create bhupi and aman at the same time. If I use mkdir without argument, it will give an error. So to remove the error, we have to use -p argument. See in the picture.

mkdir -p bhupi/aman
mkdir -p command in Linux
creating directory inside the directory with mkdir command using -p argument.

Specify the permission while creating a directory

You can also define permission while creating a directory. There is -m argument that helps to set the permissions while you are creating the directory. So, you can see in the example below. If you want to learn about permission, then you can click on the link necessary permissions in Linux

mkdir -m a=rwx direcories_name

To show you, I’m creating a directory with reading and writing permission, and you can see the example command in the picture.

mkdir -m a=rw ram
mkdir command in Linux
creating directory along with defined permissions

Conclusion

In this article, you learned about the mkdir command, and you can see that it is easy to use and you get a lot of information. I hope you understand, but if you have any questions, you can ask in the comment section.

One comment

Leave a Reply

Your email address will not be published.

  1. Like!! I blog frequently and I really thank you for your content. The article has truly peaked my interest.