-   Linux - Software (
-   -   mkdir -p ? (

shanenin 01-22-2004 01:53 PM

mkdir -p ?
I read the man pages about the command mkdir -p , I still am haveing trouble understanding it. Below is an excerpt from man mkdir

-p, --parents
Make any missing parent directories for each directory argument.
The mode for parent directories is set to the umask modified by
`u+wx'. Ignore arguments corresponding to existing directories.
(Thus, if a directory /a exists, then `mkdir /a' is an error,
but `mkdir -p /a' is not.)

ricstirato 01-22-2004 02:07 PM

Here is an example:

you already have a directory:


you want a subdirectory c, which is in b, which is in a:


A "mkdir /a/b/c" will fail, because it tries to create c in /a/b - and b does not yet exist.

You might use:

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

or simply

mkdir -p /a/b/c

which will create b, because it does not exist.

shanenin 01-22-2004 02:12 PM

thanks you made that very clear. I always thought their had to be an easier way of making a directory then multilple mkdir commands.:)

Fagadaba 10-19-2011 05:23 AM

7 years later, from Google!
I am posting this here reply because this page is the first non-man answer for an "mkdir -p" query on Google.
To give some useful information/tip for all the noobs stumbling on here like I did.

You can use "mkdir -p" and the power of BRACES to create the biggest complexst hierarchies of directories you've ever dreamed of in one command!

Like so:

mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
Which creates the following:

  |        |      |
branches  tags  trunk
              |          |
          includes    docs


Source: Wikipedia - mkdir

More info and examples here.

Tinkster 10-19-2011 12:41 PM

Introducing yourself to LQ by swearing in a necropost and
being reported for that. Nice. :}

And your version is simply a slightly more verbatious
explanation of the quote from the man-page in the first
response ...

Welcome, anyway.


All times are GMT -5. The time now is 12:47 AM.