Red Hat Bugzilla – Bug 500195
mkdir -p does not honour -m
Last modified: 2009-05-11 13:19:32 EDT
Description of problem:
When creating a directory structure with mkdir using -p, the mode set with -m is only applied to the last directory in the chain, not the intermediate directories.
[sun@lain ~ :) 1]$ umask
[sun@lain ~ :) 2]$ mkdir foo
[sun@lain ~ :) 4]$ ls -ld foo
drwx------ 2 sun users 4096 2009-05-11 17:39 foo
[sun@lain ~ :) 5]$ mkdir -m 755 bar
[sun@lain ~ :) 6]$ ls -ld bar
drwxr-xr-x 2 sun users 4096 2009-05-11 17:40 bar
[sun@lain ~ :) 7]$ rm -rf foo bar
[sun@lain ~ :) 8]$ mkdir -m 755 -p foo/bar
[sun@lain ~ :) 9]$ ls -ld foo foo/bar
drwx------ 3 sun users 4096 2009-05-11 17:40 foo
drwxr-xr-x 2 sun users 4096 2009-05-11 17:40 foo/bar
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. see above
Mask is only applied to last directory
Mask applied to all created directories
Thanks for report. According to POSIX (http://www.opengroup.org/onlinepubs/009695399/utilities/mkdir.html) that's exactly the way how mkdir should behave.
POSIX states that with -p and -m option parent directory creation should behave like `mkdir -p -m $(umask -S),u+wx $(dirname dir) &&
mkdir [-m mode] dir` - and that's the way how it behaves now. If you think that my POSIX interpretation is wrong, feel free to discuss it here.
Closing NOTABUG as the current behaviour does comply with POSIX requirements...
I think your interpretation of the POSIX standard is correct, it is just not what I'd expect it to do. The info page actually mentiones this behaviour, but who reads info pages?
In the case of coreutils are info pages quite useful - as manpages of coreutils commands are only help2man-ed --help outputs of commands. But you are right - many users do ignore info pages... Maybe --help/man page improvement could be suggested on firstname.lastname@example.org (upstream bugreport/discussion mailing list) - to state that only final directory is affected by -m mode.