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

11 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:
    March 29th, 2025 at 16:13

    … [Trackback]

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

  5. Matthew Says:
    March 30th, 2025 at 02:13

    … [Trackback]

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

  6. provadent reviews Says:
    March 31st, 2025 at 10:19

    Hey would you mind letting me know which web host you’re using?
    I’ve loaded your blog in 3 different internet browsers and I must say this blog loads a lot faster then most.

    Can you suggest a good internet hosting provider at a fair price?
    Thanks a lot, I appreciate it!

    Also visit my web blog – provadent reviews

  7. nitric boost ultra reviews Says:
    March 31st, 2025 at 12:42

    What’s up, always i used to check website posts here in the early hours in the daylight, since i love to find
    out more and more.

    Also visit my page: nitric boost ultra reviews

  8. บาคาร่า ufa11k Says:
    April 11th, 2025 at 03:59

    … [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. ricky casino Says:
    April 11th, 2025 at 09:34

    … [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/ […]

  10. the memory wave reviews Says:
    April 11th, 2025 at 10:19

    Hey very interesting blog!

    My page; the memory wave reviews

  11. does tonic greens get rid of herpes Says:
    April 14th, 2025 at 06:25

    Hi there everyone, it’s my first pay a quick visit at this web site, and
    piece of writing is actually fruitful in support of me, keep up posting these types
    of posts.

    Feel free to surf to my page :: does tonic greens get rid of herpes

Comments