LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-25-2006, 05:11 AM   #1
George2
Member
 
Registered: Oct 2003
Posts: 354

Rep: Reputation: 30
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
 
Old 04-25-2006, 05:15 AM   #2
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
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.
 
Old 04-25-2006, 05:24 AM   #3
T.Hsu
Member
 
Registered: Jan 2005
Posts: 178

Rep: Reputation: 31
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.
 
Old 04-25-2006, 06:30 AM   #4
George2
Member
 
Registered: Oct 2003
Posts: 354

Original Poster
Rep: Reputation: 30
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
 
Old 04-25-2006, 06:33 AM   #5
George2
Member
 
Registered: Oct 2003
Posts: 354

Original Poster
Rep: Reputation: 30
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to make a directory with mkdir using the date command. Altheastronut Linux - General 5 06-09-2009 12:14 PM
cp command: except or ignore option? C-RAF. Programming 9 02-28-2006 03:23 AM
Command line option -F means what? TSynergy Linux - Newbie 5 11-15-2005 08:01 PM
mkdir command digitalgravy Linux - General 5 08-12-2004 01:03 PM
can I use date command with mkdir? ewto Linux - General 6 06-16-2004 08:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration