LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   About -p Option Of Mkdir Command (https://www.linuxquestions.org/questions/linux-software-2/about-p-option-of-mkdir-command-438595/)

George2 04-25-2006 05:11 AM

About -p Option Of Mkdir Command
 
Hello everyone,


I have read through the Linux man page and also info page of -p option of mkdir command. But I still do not understand what it means, especially missing parent directories.

Could anyone show me an example about how to use -p please?


thanks in advance,
George

reddazz 04-25-2006 05:15 AM

Lets say I want to create a subdirectory called linux in a directory called games. If games doesn't already exist, I can do "mkdir games" and then cd into games and do "mkdir linux". An easier way would be to do "mkdir -p games/linux". This creates games (the parent) as well as a subdirectory called linux at the same time.

T.Hsu 04-25-2006 05:24 AM

Example:

Code:

test -d $HOME/test || echo "Not exist"
Not exist
mkdir -p $HOME/test/foo/bar
test -d $HOME/test/foo/bar && { echo "Exist"; } || echo "Not exist"
Exist

You see, `mkdir -p' creates directory's parent even "grand parent" directory when they are missing.

George2 04-25-2006 06:30 AM

Thank you, reddazz!


Quote:

Originally Posted by reddazz
Lets say I want to create a subdirectory called linux in a directory called games. If games doesn't already exist, I can do "mkdir games" and then cd into games and do "mkdir linux". An easier way would be to do "mkdir -p games/linux". This creates games (the parent) as well as a subdirectory called linux at the same time.

You have answered my question.


regards,
George

George2 04-25-2006 06:33 AM

Thanks T.Hsu!


Quote:

Originally Posted by T.Hsu
Example:

Code:

test -d $HOME/test || echo "Not exist"
Not exist
mkdir -p $HOME/test/foo/bar
test -d $HOME/test/foo/bar && { echo "Exist"; } || echo "Not exist"
Exist

You see, `mkdir -p' creates directory's parent even "grand parent" directory when they are missing.

Now I understand that -p is used to created upper level directories if they do not exist. I have also tested on my Linux machine that if -p is not specified and the upper level directories do not exist, mkdir will return error.


regards,
George


All times are GMT -5. The time now is 02:18 AM.