LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   mkdir -p ? (http://www.linuxquestions.org/questions/linux-software-2/mkdir-p-137500/)

shanenin 01-22-2004 12: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
Quote:

-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 01:07 PM

Here is an example:

you already have a directory:

/a

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

/a/b/c

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 01: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 04: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:
Code:

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

          tmpdir
    ________|______
  |        |      |
branches  tags  trunk
                  |
                sources
              ____|_____
              |          |
          includes    docs

CRAZY HUH?!

Source: Wikipedia - mkdir

More info and examples here.

Tinkster 10-19-2011 11:41 AM

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.


Cheers,
Tink


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