Tuesday, March 20, 2012

Useful Linux Command - mkdir -p

-p (parents) option for mkdir gives you the ability to create a multiple levels deep directory with all the intermediate directories created as well.

Example: When you want to create a directory tree like this /a/b/c/d, where a,b,c,d are all not exist before, you need to create each directory independently like

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

if you do mkdir /a/b/c/d, you will encounter "no such file or directory" error.

With -p option, you can create /a/b/c/d with just one single line of command as shown below:

mkdir -p /a/b/c/d