Creating Multiple Folders in One Command in Linux
There are two ways that can be used to create a new folder on the GNU/Linux Operating System. First, using File Manager like Nautilus, Dolphin, Thunar and so on by right-clicking, and then selecting a new folder. The second way is to use the command mkdir past Terminal.
Mkdir is a command line used to create a new folder or directory on Linux. Not only on Linux, command mkdir also exists on Windows and OS X which also serves to create new folders or directories.
Example of using the command mkdir on Linux:
mkdir /home/pemrograman
The command means a folder named programming has been created in the directory /home.
But what if you are required to create a folder that has a more complex directory structure. For example in the folder programming there are other folders, namely; bash, c, javascript, java, ruby, and python. Then inside the folder ruby there are subfolders railsand in the folder python there is a folder python2 and python3as well as in folders python3 there are subfolders django. For more details, see the following picture
![]() |
| Folder Directory Structure to be Created |
To create these folders, basically you have to use the command line like this:
sudo mkdir /home/pemrograman/bash sudo mkdir /home/pemrograman/c sudo mkdir /home/pemrograman/java sudo mkdir /home/pemrograman/javascript sudo mkdir /home/pemrograman/ruby sudo mkdir /home/pemrograman/ruby/rails sudo mkdir /home/pemrograman/python/python2 sudo mkdir /home/pemrograman/python/python3 sudo mkdir /home/pemrograman/python/python3/django
It takes that many commands to create a folder or directory like the scenario that has been planned. But actually there is a very effective and efficient way to easily create a folder or directory in just one command line, as follows:
sudo mkdir -p /home/pemrograman/{bash,c,java,javascript,python/{python2, python3/django},ruby/rails}
By using option -p and curly brackets ({}) for hierarchy from the directory, complex jobs like those scenarios can be completed in a single command line. This method is very useful and effective to save time and effort.
To check the directory structure that has been created is successful, you can use the command trees. But usually tree must be installed first.
Use the following command to check the directory structure that was created:
tree /home/pemrograman
Then the directory structure will appear as previously created. Safe!
![]() |
| Created Folder Directory Structure |

