Skip to content

[Linux] Use mkdir Command To Make Recursive Folders

mkdir must be one of the most commonly used commands on Linux system, and its function is to create a folder (directory).

However, I have seen before that Linux users who are not familiar enough with this command have painstakingly created layer after layer of folders.

What does that mean? In fact, the directory he/she needs should be:

dir_1/dir_2/dir_3/dir_4


So, he/she use the following command to do it:

mkdir dir_1
mkdir dir_1/dir_2
mkdir dir_1/dir_2/dir_3
mkdir dir_1/dir_2/dir_3/dir_4

Use -p (–parents) parameter to make a recursive folder

If you check the manual page of mkdir:

man mkdir


You will read the official instruction manual, which records:

-p, --parents
       no error if existing, make parent directories as needed


That is to say, we enter the path of the production folder, if there is no parent folder, it will be created automatically.

In other words, we only need to use:

mkdir -p dir_1/dir_2/dir_3/dir_4


Output:


References


Read More

Tags:

1 thought on “[Linux] Use mkdir Command To Make Recursive Folders”

Leave a Reply