Is mkdir -p totally safe when creating folder already exists

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
7
down vote

favorite
1












Say I have a folder:



./folder/



Inside it there are many files and even sub-directories.



When I execute:



mkdir -p folder



I won't see any errors even warnings. so just want to confirm, is there anything lost or changed in result of this command?










share|improve this question

















  • 2




    The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
    – Marco
    Nov 14 '15 at 13:29














up vote
7
down vote

favorite
1












Say I have a folder:



./folder/



Inside it there are many files and even sub-directories.



When I execute:



mkdir -p folder



I won't see any errors even warnings. so just want to confirm, is there anything lost or changed in result of this command?










share|improve this question

















  • 2




    The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
    – Marco
    Nov 14 '15 at 13:29












up vote
7
down vote

favorite
1









up vote
7
down vote

favorite
1






1





Say I have a folder:



./folder/



Inside it there are many files and even sub-directories.



When I execute:



mkdir -p folder



I won't see any errors even warnings. so just want to confirm, is there anything lost or changed in result of this command?










share|improve this question













Say I have a folder:



./folder/



Inside it there are many files and even sub-directories.



When I execute:



mkdir -p folder



I won't see any errors even warnings. so just want to confirm, is there anything lost or changed in result of this command?







mkdir






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '15 at 13:14









AGamePlayer

1,881102942




1,881102942







  • 2




    The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
    – Marco
    Nov 14 '15 at 13:29












  • 2




    The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
    – Marco
    Nov 14 '15 at 13:29







2




2




The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
– Marco
Nov 14 '15 at 13:29




The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
– Marco
Nov 14 '15 at 13:29










3 Answers
3






active

oldest

votes

















up vote
9
down vote



accepted










mkdir -p would not give you an error if the directory already exists and the contents for the directory will not change.



Manual entry for mkdir






share|improve this answer


















  • 1




    This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
    – Aaron Cicali
    Jul 19 '16 at 2:35










  • in error, you could check for the code like this if(err.code == 'EEXIST') this condition will get true if the directory already exists.
    – user403173
    Aug 2 at 6:53

















up vote
11
down vote













A portable script will rely upon POSIX, which says of mkdir's -p option:




Each dir operand that names an existing directory shall be ignored without error.




and if there are no errors reported, the -p option has done its job:




Create any missing intermediate pathname components.







share|improve this answer





























    up vote
    3
    down vote













    mkdir WILL give you an error if the directory already exists.



    mkdir -p WILL NOT give you an error if the directory already exists. Also, the directory will remain untouched i.e. the contents are preserved as they were.






    share|improve this answer




















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f242995%2fis-mkdir-p-totally-safe-when-creating-folder-already-exists%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      9
      down vote



      accepted










      mkdir -p would not give you an error if the directory already exists and the contents for the directory will not change.



      Manual entry for mkdir






      share|improve this answer


















      • 1




        This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
        – Aaron Cicali
        Jul 19 '16 at 2:35










      • in error, you could check for the code like this if(err.code == 'EEXIST') this condition will get true if the directory already exists.
        – user403173
        Aug 2 at 6:53














      up vote
      9
      down vote



      accepted










      mkdir -p would not give you an error if the directory already exists and the contents for the directory will not change.



      Manual entry for mkdir






      share|improve this answer


















      • 1




        This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
        – Aaron Cicali
        Jul 19 '16 at 2:35










      • in error, you could check for the code like this if(err.code == 'EEXIST') this condition will get true if the directory already exists.
        – user403173
        Aug 2 at 6:53












      up vote
      9
      down vote



      accepted







      up vote
      9
      down vote



      accepted






      mkdir -p would not give you an error if the directory already exists and the contents for the directory will not change.



      Manual entry for mkdir






      share|improve this answer














      mkdir -p would not give you an error if the directory already exists and the contents for the directory will not change.



      Manual entry for mkdir







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Aug 26 at 14:05









      Community♦

      1




      1










      answered Nov 14 '15 at 13:39









      ARG

      95978




      95978







      • 1




        This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
        – Aaron Cicali
        Jul 19 '16 at 2:35










      • in error, you could check for the code like this if(err.code == 'EEXIST') this condition will get true if the directory already exists.
        – user403173
        Aug 2 at 6:53












      • 1




        This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
        – Aaron Cicali
        Jul 19 '16 at 2:35










      • in error, you could check for the code like this if(err.code == 'EEXIST') this condition will get true if the directory already exists.
        – user403173
        Aug 2 at 6:53







      1




      1




      This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
      – Aaron Cicali
      Jul 19 '16 at 2:35




      This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
      – Aaron Cicali
      Jul 19 '16 at 2:35












      in error, you could check for the code like this if(err.code == 'EEXIST') this condition will get true if the directory already exists.
      – user403173
      Aug 2 at 6:53




      in error, you could check for the code like this if(err.code == 'EEXIST') this condition will get true if the directory already exists.
      – user403173
      Aug 2 at 6:53












      up vote
      11
      down vote













      A portable script will rely upon POSIX, which says of mkdir's -p option:




      Each dir operand that names an existing directory shall be ignored without error.




      and if there are no errors reported, the -p option has done its job:




      Create any missing intermediate pathname components.







      share|improve this answer


























        up vote
        11
        down vote













        A portable script will rely upon POSIX, which says of mkdir's -p option:




        Each dir operand that names an existing directory shall be ignored without error.




        and if there are no errors reported, the -p option has done its job:




        Create any missing intermediate pathname components.







        share|improve this answer
























          up vote
          11
          down vote










          up vote
          11
          down vote









          A portable script will rely upon POSIX, which says of mkdir's -p option:




          Each dir operand that names an existing directory shall be ignored without error.




          and if there are no errors reported, the -p option has done its job:




          Create any missing intermediate pathname components.







          share|improve this answer














          A portable script will rely upon POSIX, which says of mkdir's -p option:




          Each dir operand that names an existing directory shall be ignored without error.




          and if there are no errors reported, the -p option has done its job:




          Create any missing intermediate pathname components.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '15 at 13:52

























          answered Nov 14 '15 at 13:43









          Thomas Dickey

          50.2k587157




          50.2k587157




















              up vote
              3
              down vote













              mkdir WILL give you an error if the directory already exists.



              mkdir -p WILL NOT give you an error if the directory already exists. Also, the directory will remain untouched i.e. the contents are preserved as they were.






              share|improve this answer
























                up vote
                3
                down vote













                mkdir WILL give you an error if the directory already exists.



                mkdir -p WILL NOT give you an error if the directory already exists. Also, the directory will remain untouched i.e. the contents are preserved as they were.






                share|improve this answer






















                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  mkdir WILL give you an error if the directory already exists.



                  mkdir -p WILL NOT give you an error if the directory already exists. Also, the directory will remain untouched i.e. the contents are preserved as they were.






                  share|improve this answer












                  mkdir WILL give you an error if the directory already exists.



                  mkdir -p WILL NOT give you an error if the directory already exists. Also, the directory will remain untouched i.e. the contents are preserved as they were.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 27 '17 at 14:44









                  Tushar Vazirani

                  1311




                  1311



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f242995%2fis-mkdir-p-totally-safe-when-creating-folder-already-exists%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?