Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

Very small Linux tip - Create directory trees in one command

Date: 2010-09-09 00:00:00 -0400

If you ever need to create directory trees like this

Directory Tree

You can do this:

cd /tmp

mkdir 1

cd 1

mkdir 2

cd 2

mkdir C

or, you can just do this:

mkdir -p /tmp/1/2/3

From the man page of mkdir

-p, --parents
no error if existing, make parent directories as needed

You can also use this option to create more complicated trees. Like this one.

directory tree

Do that with this:

mkdir -p /tmp/A/{1,2,B/{1,2}}

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.