This service will be undergoing maintenance at 00:00 UTC, 2016-08-01. It is expected to last about 1 hours

Bug 802697

Summary: mkdir -p ignores already created directory
Product: [Fedora] Fedora Reporter: cornel panceac <cpanceac>
Component: coreutilsAssignee: Ondrej Vasik <ovasik>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 16CC: kdudka, maxamillion, ovasik, pbrady, p, twaugh
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-03-13 06:23:28 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:

Description cornel panceac 2012-03-13 06:02:15 EDT
Description of problem:
after creating a directory, mkdir -p successfully creates again the directory that already exists.

Version-Release number of selected component (if applicable):

$ rpm -qf /bin/mkdir
coreutils-8.12-6.fc16.i686

How reproducible:
always

Steps to Reproduce:
1.mkdir -p bugz
2.mkdir -p bugz ; echo $?
3.
  
Actual results:


Expected results:
mkdir will fail, because the directory already exists

Additional info:

i've also created a file inside the directory, and after mkdir -p the file is still there.
Comment 1 Pádraig Brady 2012-03-13 06:23:28 EDT
That's expected behavior. Treat -p as "make sure it (and any parent) exists". It's akin to `touch file`.

If you want to split the parents vs exists behavior you might want:

mkdir -p $(dirname "$dir")
mkdir "$dir"

cheers.
Comment 2 cornel panceac 2012-03-13 06:38:14 EDT
This great but, where is it documented?
Comment 3 Pádraig Brady 2012-03-13 06:47:48 EDT
The man page states:

-p, --parents
   no error if existing, make parent directories as needed
Comment 4 cornel panceac 2012-03-13 06:54:25 EDT
I see, i thought it's no error if parents exist :) do you think the man page can be clarified a bit?
Comment 5 Ondrej Vasik 2012-03-13 14:00:15 EDT
Man page probably not, info documentation is intended to be a bit more wordy in such cases. In info you have:
`-p'
`--parents'
     Make any missing parent directories for each argument, setting
     their file permission bits to the umask modified by `u+wx'.  Ignore
     existing parent directories, and do not change their file
     permission bits.

- any missing seems to be quite self explaining to me, but if you prefer adjusted wording, feel free to propose a change...