« 12 things you need to know about PHP | Home | How to get the initial help on sudo to reappear in Ubuntu »
How to force mkdir to create a directory if there isn’t already one
By admin | September 3, 2008
If you’ve ever tried to make a directory if there isn’t one existing, you probably have bumped into the following error:
mkdir: cannot create directory `the_directory': File exists
To fix this, use this instead to suppress error and create parent directories if needed:
mkdir -p your_directory
For more information, see the mkdir page at Wikipedia.
If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!
Topics: Linux | 8 Comments »
April 20th, 2015 at 11:46
Thanks it worked in full go ,, can you share what p stands for
June 6th, 2016 at 02:50
-p serves to force mkdir to also create the parent directories (hence the ‘p’).
October 9th, 2019 at 06:31
what if my directory is not a parent directory
[ram@raj ~]$ mkdir opt
[ram@raj ~]$ ls
opt
[ram@raj opt]$ mkdir java
mkdir: cannot create directory ‘java’: Permission denied
[ram@raj opt]$ mkdir -p java
mkdir: cannot create directory ‘java’: Permission denied
[ram@raj opt]$
November 2nd, 2024 at 21:15
… [Trackback]
[…] Read More on that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]
November 16th, 2024 at 00:46
… [Trackback]
[…] Here you will find 33386 additional Info on that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]
November 18th, 2024 at 20:49
… [Trackback]
[…] Information to that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]
November 19th, 2024 at 04:41
… [Trackback]
[…] Here you can find 93631 additional Information on that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]
November 27th, 2024 at 04:15
… [Trackback]
[…] There you will find 39319 additional Info to that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]