Compdigitec Labs

« | Home | »

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 »

8 Responses to “How to force mkdir to create a directory if there isn’t already one”

  1. Gaurav Khurana Says:
    April 20th, 2015 at 11:46

    Thanks it worked in full go ,, can you share what p stands for

  2. admin Says:
    June 6th, 2016 at 02:50

    -p serves to force mkdir to also create the parent directories (hence the ‘p’).

  3. Rajesh Damam Says:
    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]$

  4. boat rentals Says:
    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/ […]

  5. เว็บรวมเกมสล็อต Says:
    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/ […]

  6. เทคนิคแทงบอลเต็ง ยังไงให้ได้เงิน Says:
    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/ […]

  7. โคมไฟ Says:
    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/ […]

  8. สอนภาษาไทยให้ชาวต่างชาติ Says:
    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/ […]

Comments