Unix – Make Directory Tree in a Swipe

by venukb on January 22, 2007

If I wanted to created a directory tree say /first/second/third this is how I used to do it, till now.

$ cd /
$ mkdir first
$ cd first
$ mkdir second
$ cd second
$ mkdir third
$ cd third

Today I learnt that you could do this in a single swipe using the -p option!

mkdir -p first/second/third

And its not just restricted to simple hierarchies, you could even create a complex tree structure like this

$ mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}

You can find 9 more such interesting tips on the IBM post titled “Learn 10 good UNIX usage habits

{ 2 comments… read them below or add one }

rushita February 19, 2010 at 6:10 pm

thanks it was helpful :) xx

Reply

Sharat Chandran November 11, 2010 at 4:22 pm

Hey Venu,

This is awesome man!! Thanks a tonne. It really solved a biigg issue for me today!
Thanks again!

Reply

Leave a Comment

 

Previous post:

Next post: