I like to present a challenge to my software engineer friends: can you
tell me what this command does on Linux, if run in an empty directory?
mkdir -m 0755 -p ./usr/bin/foo
If they read the mkdir man page (
https://man7.org/linux/man-pages/man1/mkdir.1.html), they almost always say
the answer is:
- create the directory ./usr, with the mode 0755
- create the directory ./usr/bin, with the mode 0755
- create the directory ./usr/bin/foo, with the mode 0755
They are wrong. (Side note -- this misunderstanding contributed to one of
the scariest outages Google has ever seen,
https://www.pdl.cmu.edu/SDI/2012/083012b.html).
What it actually does:
- create the directory ./usr, with the mode based on the umask
- create the directory ./usr/bin, with the mode based on the umask
- create the directory ./usr/bin/foo, with the mode 0755
I tried at the time to get the man page corrected, but I was told at the
time that nobody reads man pages, and the info page is correct, so it won't
be fixed.
I figured after almost 10 years, perhaps thinking has evolved. Can we fix
the man page?
I have a suggested fix: the current man page reads:
-p, --parents
no error if existing, make parent directories as needed
I can be updated to read:
-p, --parents
no error if existing, make parent directories as needed,
setting
their file permission bits to the umask modified by ‘u+wx’.
I copied the new text from the info page.
Thanks!
Chris