How to Create Directory Structure using Terminal

In this article, we are going to see how to create a directory structure using terminal.

The “mkdir” command  is used to create a folder or a directory using terminal. Now for creating a folder within another folder (multilevel directory structure), if  you use the “mkdir” command like the following command, you will get one error message like this “mkdir: dir1/dir2: No such file or directory”.

$ mkdir dir1/dir2/dir3

Now if you want the terminal to create the structure itself when you try to create a directory, you will have to use the command like this :

$ mkdir -p dir1/dir2/dir3

This will first create the directory, “dir1”, then inside dir1, it will create the directory “dir2” and finally inside dir2, it will create the directory “dir3”.