Creating a directory in linux is simple and a crucial task. These directories fundamentally help you to keep things in an order. It’s more like an organization tool that helps you organize other directories and files.
How to Create a Directory in Linux Step-by-Step
Step 1: Fire up your terminal which you can do by pressing ‘CTRL+ALT+T’ or by right clicking on your screen and selecting ‘Open in Terminal’:
Step 2: Make sure you are in the right location where you want to create the directory, if not then you can always change your current directory to the desired location, I want to create directory on my desktop:
$ cd /Desktop
Step 3: Now simply use ‘mkdir’ command to create your directory, this will create the directory in our current working directory which in our case is ‘Desktop’:
$ mkdir New_Directory
Step 4: Go ahead and verify if the directory was created successfully by using ‘ls’ command:
$ ls
How to Create Multiple Directories
In 4 simple steps, we learned how to create a directory in linux, but what if we want to create multiple directories at once? How do we do that? It’s not that difficult, simply keep adding names of as many directories as you want with a space between them one after another. Let’s say I wanna create 3 directories, all I have to do is:
$ mkdir Dir1 Dir2 Dir3
How to Create Nested Directories
What if you want to create directories inside of the directories at once? You can do so by using the following command:
$ mkdir -p project/myapp/files
‘-p’ is the flag that lets you create a parent directory which then helps you create all directories within.
If you want to learn about permissions in Linux then you can learn from here:
- How to Give Full Permission to Folder and Subfolder?
- What Does File Permission 755 Mean?
- Understanding Linux File Permissions
Conclusion
You have learned 4 steps to create a directory, then you have also learned how to create multiple directories and finally you have learned how to create nested directories where you created directories within directories. Checkout the permission articles I have linked above this conclusion, the way to change permissions for files and directories is essentially the same so it doesn’t matter if you are reading a file permission article, it can be applied to directories too.
Check our LinkedIn company page