[SOLVED] mkdir with -p and -m does not honor -m all the way
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
mkdir with -p and -m does not honor -m all the way
Hi folks,
I found some odd behaviour of mkdir in conjunction with -m and -p. Setting the mode to 0700 only the last directory is created with the right permission. higher up directories get the default umask. All this on debian squeeze.
Is this the same for other distributions?
Is this expected behaviour?
`-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.
To set the file permission bits of any newly-created parent
directories to a value that includes `u+wx', you can set the umask
before invoking `mkdir'. For example, if the shell command
`(umask u=rwx,go=rx; mkdir -p P/Q)' creates the parent `P' it sets
the parent's permission bits to `u=rwx,go=rx'. To set a parent's
special mode bits as well, you can invoke `chmod' after `mkdir'.
*Note Directory Setuid and Setgid::, for how the set-user-ID and
set-group-ID bits of newly-created parent directories are
inherited.
This is normal behaviour, which I've seen on, amongst others, RedHat, LFS and Debian.
I agree that it would be nice to have an extra options that sets the permissions on the whole range of directories that are created, but I do see the logic of the current behaviour of the combined -p and -m options.
Also --mode mentions "created directories" but I guess this only applies if multiple directories are created and not the -p option.
Thanks Firerat. I mark as solved.
@druuna: I'd rather have it the default if -m is given that all the directories get that permission. I guess there are pros and cons depending on what one wants to do. In my case the mode should be applied all the way cause its just one plain way. But for example creating log files like mkdir -p /var/log/olddir/{syslog,exim,someother,stuff} for logrotation I sure want olddir to be umask'ed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.