Bug 802697 - mkdir -p ignores already created directory
mkdir -p ignores already created directory
Product: Fedora
Classification: Fedora
Component: coreutils (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Ondrej Vasik
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2012-03-13 06:02 EDT by cornel panceac
Modified: 2012-03-13 14:00 EDT (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2012-03-13 06:23:28 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
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

How reproducible:

Steps to Reproduce:
1.mkdir -p bugz
2.mkdir -p bugz ; echo $?
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"

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:
     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...

Note You need to log in before you can comment on or make changes to this bug.