Create Multiple Nested Directories in Linux At Once

Did you know that you can create a complete directory tree with one command?
Let’s start with a simple example:

mkdir -p a/b/c

will create this tree:

.
└── a
    └── b
        └── c

And any of these:

mkdir -p a/{b1,b2}/c

or

mkdir -p a/b{1,2}/c

Will create this tree:

.
└── a
    ├── b1
    │   └── c
    └── b2
        └── c

And a little more complicated command:

mkdir -p a/b{1,2,3/c{1,2}}/d

Will create this tree:

.
└── a
    ├── b1
    │   └── d
    ├── b2
    │   └── d
    └── b3
        ├── c1
        │   └── d
        └── c2
            └── d

Lastly, this more realistic example:

mkdir -p doc/{text/,img/{wallpaper/,photos/}}

Will create this tree:

.
└── doc
    ├── img
    │   ├── photos
    │   └── wallpaper
    └── text

:)

Leave a Reply