How to create nested directory in a single command?

232,308

Solution 1

The command you are looking for is mkdir -p x/y/z. The -p switch create parents directories.

~$ mkdir -p d/s/a/e
~$ cd d/s/a/e/
~/d/s/a/e$ 

Solution 2

Use the -p option. Your command should be:

sudo mkdir -p x/y/z
Share:
232,308

Related videos on Youtube

BaltoStar
Author by

BaltoStar

Updated on September 18, 2022

Comments

  • BaltoStar
    BaltoStar almost 2 years

    Apparently, it's not possible to create a nested directory in a single command?

    $ sudo mkdir x/y/z
    mkdir: cannot create directory 'x/y/z': No such file or directory
    
  • Rahul Lakhanpal
    Rahul Lakhanpal over 7 years
    This is the best answer.