How To Make Directory Recursive Command Line Make Directory Recursive mkdir -p

On occasion, like when working with ZendFramework, you may want to build a directory tree.
Did you know you can build a recursive directory tree?
Here’s how:

mkdir normaly works like this:

promt$> mkdir directory-name

directory-name

To build a directory and another directory inside of it you can do the following:

promt$> mkdir -p parent-directory/child-directory

directory-name/
    child-directory

You can even make a grandchild directory.

promt$> mkdir -p parent-directory/child-directory/grandchild-directory

directory-name/
    child-directory/
         grandchild-directory

Use the tree command to see the directory tree.
If you’re on a mac, you can install the tree command with brew.

promt$>brew install tree

Then try this:

promt$> tree parent*

parent-directory
└── child-directory
    └── grandchild-directory

Leave a Reply

Your email address will not be published.