Problem scenario: You want to create a nested directory structure like dir1/dir2/dir3. But none of these directories exists. So, you will encounter an error like this:
mkdir: cannot create directory 'dir1/dir2/dir3': No such file or directory
This is because, by default, mkdir command cannot make nested directories if the parent directory doesn’t exist.
How do I create nested directory structure in Linux command line?
Good thing is that mkdir command is actually capable of creating nested directories. All you need to do is to use the option -p. This will let you created the directory structure. If the parent directory doesn’t exist, it will create it:
mkdir -p dir1/dir2/dir3
That’s it. I hope this quick Linux command line tip helps you.