LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 07-15-2013, 06:11 AM   #1
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
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?

I go around this now in setting umask explicit.
 
Old 07-15-2013, 06:28 AM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
looking at
Code:
info coreutils 'mkdir invocation'
yields
Code:
`-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 coreutils 8.13, on Debian Jessie
 
1 members found this post helpful.
Old 07-15-2013, 06:34 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
1 members found this post helpful.
Old 07-15-2013, 06:46 AM   #4
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748

Original Poster
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
I only checked the manpage. I always forget info.

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.

I just have to remember that behaviour.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
In honor of April 1st haertig Linux - Software 2 04-02-2013 12:55 AM
[SOLVED] mkdir: cannot creat directory. How to enable mkdir for user in usb dir? Foxbat1155 Linux - Newbie 13 02-16-2012 11:20 AM
how to give options like '-v' for mkdir using system call mkdir() ? nehapawar Linux - Newbie 2 02-05-2010 02:13 AM
Medal of Honor... Linux~Powered Linux - Games 1 01-12-2005 12:46 AM
Medal of Honor Beta darksvr Linux - Software 1 12-13-2003 02:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration