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

5 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. Trustbet Says:
    March 15th, 2024 at 22:10

    … [Trackback]

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

  5. รับเขียนโปรแกรม Says:
    March 27th, 2024 at 23:09

    … [Trackback]

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

Comments