Create Multiple Nested Directories in Linux

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

:)

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

No related posts.

Tags: , ,

Friday, July 3rd, 2009 Bash

2 Comments to Create Multiple Nested Directories in Linux

  • Matt LaChance says:

    Thanks! Very handy.

  • Sakthi says:

    Thank you so much! It saved my time!

  • Leave a Reply

    my email
    my photo
    Hi,
    My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
    I'm a Verification Engineer in Mellanox Technologies Ltd.
    I love Linux, the Command Line and the OpenSource Community.
    I used to write Poems (Arabic) when I was able to find time for this.
    July 2009
    S M T W T F S
    « Jun   Sep »
     1234
    567891011
    12131415161718
    19202122232425
    262728293031  
    SEO Powered by Platinum SEO from Techblissonline

    Twitter links powered by Tweet This v1.7.4, a WordPress plugin for Twitter.