Bug 802697 - mkdir -p ignores already created directory
Summary: mkdir -p ignores already created directory
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: coreutils
Version: 16
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Ondrej Vasik
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-03-13 10:02 UTC by cornel panceac
Modified: 2012-03-13 18:00 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-03-13 10:23:28 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description cornel panceac 2012-03-13 10:02:15 UTC
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 10:23:28 UTC
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 10:38:14 UTC
This great but, where is it documented?

Comment 3 Pádraig Brady 2012-03-13 10:47:48 UTC
The man page states:

-p, --parents
   no error if existing, make parent directories as needed

Comment 4 cornel panceac 2012-03-13 10:54:25 UTC
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 18:00:15 UTC
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...


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