Red Hat Bugzilla – Bug 802697
mkdir -p ignores already created directory
Last modified: 2012-03-13 14:00: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
Steps to Reproduce:
1.mkdir -p bugz
2.mkdir -p bugz ; echo $?
mkdir will fail, because the directory already exists
i've also created a file inside the directory, and after mkdir -p the file is still there.
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")
This great but, where is it documented?
The man page states:
no error if existing, make parent directories as needed
I see, i thought it's no error if parents exist :) do you think the man page can be clarified a bit?
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
- any missing seems to be quite self explaining to me, but if you prefer adjusted wording, feel free to propose a change...