Operating System - HP-UX
1824000 Members
3918 Online
109667 Solutions
New Discussion юеВ

mkdir -m 775 -p does NOT get parent permissions?

 
SOLVED
Go to solution
A. Daniel King_1
Super Advisor

mkdir -m 775 -p does NOT get parent permissions?

Hi, folks.

I've got a small problem with parental permissions.

[/tmp:]$ ll foo
foo not found
[/tmp:]$ mkdir -m 755 -p foo/bar
[/tmp:]$ ll -d foo foo/bar
drwx------ 3 dking users 96 Jun 22 18:20 foo
drwxr-xr-x 2 dking users 96 Jun 22 18:20 foo/bar

Why does the parent not get the permissions?

[/tmp:]$ ll -d foo2 foo2/bar2
foo2 not found
foo2/bar2 not found
[/tmp:]$ umask 000 ; mkdir -m 755 -p foo2/bar2
[/tmp:]$ ll -d foo2 foo2/bar2
drwxrwxrwx 3 dking users 96 Jun 22 18:23 foo2
drwxr-xr-x 2 dking users 96 Jun 22 18:23 foo2/bar2

Any help would be appreciated!
Command-Line Junkie
5 REPLIES 5
Sridhar Bhaskarla
Honored Contributor
Solution

Re: mkdir -m 775 -p does NOT get parent permissions?

Hi Daniel,

From the man page of mkdir

// For each directory name in the pathname prefix of the
dirname argument that is not the name of an existing
directory, the specified directory is created using
the current umask setting, except that the equivalent
of chmod u+wx is done on each component to ensure
that mkdir can create lower directories regardless of
the setting of umask. //

Hope that clarified your question.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sundar_7
Honored Contributor

Re: mkdir -m 775 -p does NOT get parent permissions?


-m mode After creating the directory as specified, the file
permissions are set to mode, which is a symbolic mode
string as defined for chmod (see chmod(1)). The
umask(1) has precedence over -m.

-p Intermediate directories are created as necessary.
Otherwise, the full path prefix of dirname must
already exist. mkdir requires write permission in
the parent directory.

For each directory name in the pathname prefix of the
dirname argument that is not the name of an existing
directory, the specified directory is created using
the current umask setting, except that the equivalent
of chmod u+wx is done on each component to ensure
that mkdir can create lower directories regardless of
the setting of umask. Each directory name in the
pathname prefix of the dirname argument that matches
an existing directory is ignored without error. If
an intermediate path component exists, but has
permissions set to prevent writing or searching,
mkdir fails with an error message.

If the -m option is used, the directory specified by
dirname (excluding directories in the pathname
prefix) is created with the permissions specified by
mode.
Learn What to do ,How to do and more importantly When to do ?
Kiyoshi Miyake
Frequent Advisor

Re: mkdir -m 775 -p does NOT get parent permissions?

hi,

mkdir command works such.
how about writing as follows.

$ env umask=755 mkdir -p foo/bar

thanks.
A. Daniel King_1
Super Advisor

Re: mkdir -m 775 -p does NOT get parent permissions?

This seems to be the answer:

umask 002 ; mkdir -m 775 -p foo/bar

Thanks, all.
Command-Line Junkie
Sridhar Bhaskarla
Honored Contributor

Re: mkdir -m 775 -p does NOT get parent permissions?

Hi Daniel,

Yes in your case but not always. The key is

//the specified directory is created using
the current umask setting, except that the equivalent
of chmod u+wx is done on each component to ensure
that mkdir can create lower directories regardless of
the setting of umask//

#umask 222
#mkdir parent1
#mkdir -p -m 555 parent2/child
#ll
total 0
dr-xr-xr-x 2 root sys 96 Jun 23 09:30 parent1
drwxrwxrwx 3 root sys 96 Jun 23 09:30 parent2
#ll parent2
total 0
dr-xr-xr-x 2 root sys 96 Jun 23 09:30 child


-Sri
You may be disappointed if you fail, but you are doomed if you don't try