Quick Tip: Create a Whole Dir Path with One Stroke

The UNIX mkdir has a -p option that will automatically make any parent folders that do not already exist. So, instead of doing this:

mkdir a
mkdir a/b
mkdir a/b/c

just do this:

mkdir -p a/b/c

Not only is this a timesaver, it’s also considered good form. It’s more succinct, and it better expresses the idea that the a and b folders might already exist.

Trackbacks & Pings


  1. Does any one know how to make it step by 1
    example :
    mkdir -p 1/2/3/4/….. etc I need it to go to 1000 and ctrl c I could stop it

  2. Ace, you could write a bash script to do this incrementing for you. I’m not very eloquent in bash, but it shouldn’t be too hard to figure out.

    Just not sure why you’d want to have nested folders hundreds of levels deep. ?

  3. Its quite simple. You can do the following.



    while [ $i -le 100 ]; do
    mkdir $i;
    cd $i;

  4. Just fyi, this is default behaviour for the Windows version of mkdir.


    mkdir c:\a\b\c\d

    Will create the whole tree

  5. Thank you! This is immediately useful to me!

  6. anyone knows how to create a script that will produce a file of the pwd to text? I am at my whits end on figuring this out and i was told that did my script wrong. this is what i have:

    cd / pwd >>
    ls -lt >>

    really don’t know if I am doing this right or what, but I could use all the help I can get.

  7. Hello site owner i see you put a lot of work in your blog’s content,
    i know how to make your blogging easier, do you
    know that you can copy any content from any website, make it 100% unique and pass
    copyscape test? For more info , just type in google – rewriter creates an unique
    article in a minute

  8. FYI, this doesn’t work if you specify the entire absolute path, only the relative path.

    so if I’m in /home/user/
    and I do mkdir -p 1/2/3

    it will work
    but if I try this:
    mkdir -p /home/user/1/2/3

    it will say /home/user/1 doesn’t exist

  9. Los mandalas enseƱan al ejercitante a ordenar el propio caos interior
    de la persona que lo confecciona.

  10. Hi admin, i must say you have very interesting articles
    here. Your page should go viral. You need initial traffic boost only.
    How to get it? Search for: Mertiso’s tips go viral

  11. I have noticed you don’t monetize your website, don’t waste your
    traffic, you can earn extra cash every month because you’ve got hi quality content.

    If you want to know how to make extra $$$, search for: best adsense alternative Wrastain’s

Post a Comment

Your email is never published nor shared. Required fields are marked *

© 2006-2007 Maxim Software Corp.  All rights reserved.