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 | 14 Comments »

14 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. บริษัท กรีนพลัส (ไทยแลนด์) จำกัด Says:
    February 10th, 2022 at 11:35

    … [Trackback]

    […] Information to that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]

  5. door installation belchertown ma Says:
    February 14th, 2022 at 15:53

    … [Trackback]

    […] Information to that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]

  6. Esport Says:
    February 15th, 2022 at 19:17

    … [Trackback]

    […] Find More to that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]

  7. สล็อตวอเลท ไม่มีขั้นต่ำ Says:
    May 21st, 2022 at 20:07

    … [Trackback]

    […] Here you can find 4585 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. cvv site Says:
    June 7th, 2022 at 12:55

    … [Trackback]

    […] Find More here on that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]

  9. contactos mujeres Says:
    June 30th, 2022 at 00:34

    … [Trackback]

    […] Information on that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]

  10. red havanese Says:
    August 2nd, 2022 at 07:36

    … [Trackback]

    […] Info on that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]

  11. Super People hacks Says:
    August 8th, 2022 at 21:01

    … [Trackback]

    […] Find More on on that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]

  12. sbobet Says:
    August 11th, 2022 at 13:06

    … [Trackback]

    […] Here you will find 18325 additional Information on that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]

  13. เงินด่วน Says:
    October 3rd, 2022 at 13:52

    … [Trackback]

    […] Read More to that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]

  14. คลิปหลุดใหม่ Says:
    October 28th, 2022 at 04:48

    … [Trackback]

    […] Info on that Topic: compdigitec.com/labs/2008/09/03/how-to-force-mkdir-to-create-a-directory-if-there-isnt-already-one/ […]

Comments