create directory in linux | mkdir command | with examples
![]() |
mkdir command in linux |
Hey, guys welcome In this session, you will learn how you can use mkdir command in Linux. you can use mkdir command to create directories in Linux.
Create a directory or folder
$mkdir folder name
For example, I want to create a directory called image. so I can just give mkdir command. Which is the command to create any directory and then the name of the directory for example image and I will press ENTER. And then it's going to create this directory called image.
Create a subdirectory
![]() |
create a subfolder |
$mkdir folderName/sub folderName
Now I want to create a subdirectory inside this image directory. I can just write mkdir once again and the directory name which already exists and then I will give the forward-slash (/) for the subdirectory.
![]() |
subdirectory |
For example, I want to create a subdirectory called picture so just say mkdir image/picture then I will press ENTER. and then when I open this image directory it has this picture directory.
Create a directory and subdirectory using a flag
![]() |
mkdir command flag |
$mkdir -p folder/sub folder
If you want to create the subdirectory from the command or for the directory. which don't really exist. In order to create the directory structure, you need to use this "flag" to your "mkdir" command which is "-p" and this flag you can use to create a directory structure.
So this flag can be given in two ways this is the short version (-p) of giving this flag and if you want to know the full version you can just give "--parents" and if you give this command it's going to create a directory for you also subdirectory for you. Which doesn't even exist.
I'm going to just give this short flag which is "-p" and I will just press ENTER. And it's going to create this directory and when I go inside this directory there is one more directory called mark. So if you want to create a directory or subdirectory which doesn't really exist you can use "-p" with your "mkdir" command.
Create multiple sub-directories using mkdir
![]() |
mkdir to create multiple folders |
$mkdir -p folder/ {sub folders}
If you want to make or create several directories inside your parent directory. You can just write "mkdir -p" and For example, I want to create some directories with some names inside this names directory.
So I will just give the name of the directory and then I will just give these curly brackets ({}) and inside the curly brackets, I can provide the list of the directories which I want to create. And press ENTER
It will create these three directories so always remember "when you give a space it will not create the correct directory structure" you want. So you need to give the comma (,) without space. So this format of creating the multiple directories is correct without spaces
Conclusion
HAVE A NICE DAY