GNU bug report logs -
#8749
mkdir: feature request --reference
Previous Next
To reply to this bug, email your comments to 8749 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Fri, 27 May 2011 23:32:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Shaun Jackman <sjackman <at> bcgsc.ca>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Fri, 27 May 2011 23:32:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi,
mkdir has an option -m to set the permission mode of the directory. I
would find it useful for mkdir to have a --reference=FILE option that
works identically to chmod.
My primary use case for this feature is to create a shell alias:
alias mkdir='mkdir --reference=.'
so that in interactive shells, new directories are created with the same
permissions as their parent directory.
My goal is to have directories in my personal home directory to have
permission 755 and directories in my shared work space to have
permission 775, so that other members of my group may create new files
in shared directories. Files should have permission 755 so that members
of my group cannot modify files that I've created.
Thanks,
Shaun
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Sun, 29 May 2011 01:47:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 8749 <at> debbugs.gnu.org (full text, mbox):
Shaun Jackman wrote:
> My primary use case for this feature is to create a shell alias:
> alias mkdir='mkdir --reference=.'
> so that in interactive shells, new directories are created with the same
> permissions as their parent directory.
If your primary purpose is for an alias then you can do it this way:
alias mkdirchmod='mkdir -m $(stat -c %a .)'
alias mkdirchmod='install -d -m $(stat -c %a .)'
However a shell function might serve you better:
mkdirchmod() { mkdir "$@" ; chmod --reference=. "$@" ;}
But I think this task is better served by not doing it all and instead
using the technique of User Private Groups.
> My goal is to have directories in my personal home directory to have
> permission 755 and directories in my shared work space to have
> permission 775, so that other members of my group may create new files
> in shared directories. Files should have permission 755 so that members
> of my group cannot modify files that I've created.
The UPG (User Private Group) technique works very well in this
situation. There is a lot of documentation available on UPG on the
net and so I won't include a specific pointer. Search for it and you
will find a lot of information on it. And different operating systems
deal with configuring it differently and so you would want to look at
documentation for your particular system. But I highly recommend
using the technique.
I generally dislike combining the functionality of several different
commands into one command. In this case combining mkdir and chmod and
I don't see any reason they can't be used individually. Plus mkdir
already allows you to create directories with a specified permission
and this is feature creep into the area of the 'install' command which
also already allows creating directories of specified permissions.
Bob
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Mon, 30 May 2011 07:24:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 8749 <at> debbugs.gnu.org (full text, mbox):
Bob Proulx wrote:
> I generally dislike combining the functionality of several different
> commands into one command. In this case combining mkdir and chmod and
> I don't see any reason they can't be used individually. Plus mkdir
> already allows you to create directories with a specified permission
> and this is feature creep into the area of the 'install' command which
> also already allows creating directories of specified permissions.
well, 'mkdir --reference=file' could be the sister of 'touch -r file',
so creating a directory with both the perms and the timestamps of the
reference file/directory. I don't know when 'touch' has been enhanced
for '--reference' but wasn't it the same question then?
Have a nice day,
Berny
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Mon, 30 May 2011 17:30:03 GMT)
Full text and
rfc822 format available.
Message #14 received at 8749 <at> debbugs.gnu.org (full text, mbox):
Hi Bob,
I was using exactly that shell function that you described, but it
doesn't work for
mkdir -p foo/bar
I'm using the alias you gave, which works better. Thanks.
I've noticed one issue, which I feel is a bug in mkdir. When using mkdir
-pm, the specified mode is applied only to the final directory and not
the parent directories:
$ mkdir -pm 775 foo/bar
$ ls -ld foo foo/bar
drwxr-xr-x 3 sjackman assembly 4096 May 30 10:27 foo
drwxrwxr-x 2 sjackman assembly 4096 May 30 10:27 foo/bar
I would expect both foo and foo/bar to have mode 775.
Cheers,
Shaun
On Sat, 2011-05-28 at 18:46 -0700, Bob Proulx wrote:
> Shaun Jackman wrote:
> > My primary use case for this feature is to create a shell alias:
> > alias mkdir='mkdir --reference=.'
> > so that in interactive shells, new directories are created with the same
> > permissions as their parent directory.
>
> If your primary purpose is for an alias then you can do it this way:
>
> alias mkdirchmod='mkdir -m $(stat -c %a .)'
>
> alias mkdirchmod='install -d -m $(stat -c %a .)'
>
> However a shell function might serve you better:
>
> mkdirchmod() { mkdir "$@" ; chmod --reference=. "$@" ;}
>
> But I think this task is better served by not doing it all and instead
> using the technique of User Private Groups.
>
> > My goal is to have directories in my personal home directory to have
> > permission 755 and directories in my shared work space to have
> > permission 775, so that other members of my group may create new files
> > in shared directories. Files should have permission 755 so that members
> > of my group cannot modify files that I've created.
>
> The UPG (User Private Group) technique works very well in this
> situation. There is a lot of documentation available on UPG on the
> net and so I won't include a specific pointer. Search for it and you
> will find a lot of information on it. And different operating systems
> deal with configuring it differently and so you would want to look at
> documentation for your particular system. But I highly recommend
> using the technique.
>
> I generally dislike combining the functionality of several different
> commands into one command. In this case combining mkdir and chmod and
> I don't see any reason they can't be used individually. Plus mkdir
> already allows you to create directories with a specified permission
> and this is feature creep into the area of the 'install' command which
> also already allows creating directories of specified permissions.
>
> Bob
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Tue, 31 May 2011 05:05:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 8749 <at> debbugs.gnu.org (full text, mbox):
On 05/30/11 10:29, Shaun Jackman wrote:
> When using mkdir
> -pm, the specified mode is applied only to the final directory and not
> the parent directories
That behavior is required by POSIX; see
<http://pubs.opengroup.org/onlinepubs/9699919799/utilities/mkdir.html>.
Perhaps an argument could be made for a new option, which would
have the behavior you'd prefer; it'd be nice to see use cases.
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Tue, 31 May 2011 18:13:03 GMT)
Full text and
rfc822 format available.
Message #20 received at 8749 <at> debbugs.gnu.org (full text, mbox):
Hi Paul,
My use case is working in a directory shared amongst a group of users.
My umask is 022. I run
mkdir -pm775 project/subproject
and I'd like both project and project/subproject to be group-writable.
Cheers,
Shaun
On Mon, 2011-05-30 at 22:04 -0700, Paul Eggert wrote:
> On 05/30/11 10:29, Shaun Jackman wrote:
> > When using mkdir
> > -pm, the specified mode is applied only to the final directory and not
> > the parent directories
>
> That behavior is required by POSIX; see
> <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/mkdir.html>.
>
> Perhaps an argument could be made for a new option, which would
> have the behavior you'd prefer; it'd be nice to see use cases.
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Tue, 31 May 2011 20:07:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 8749 <at> debbugs.gnu.org (full text, mbox):
On 05/31/11 11:12, Shaun Jackman wrote:
> My use case is working in a directory shared amongst a group of users.
> My umask is 022. I run
> mkdir -pm775 project/subproject
You're typing stuff like that by hand? I'd expect that sort of
thing to be in a script. Either way, you can do this instead:
(umask g+w; mkdir -p project/subproject)
This is portable and doesn't require any changes to mkdir.
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Tue, 31 May 2011 20:39:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 8749 <at> debbugs.gnu.org (full text, mbox):
On Tue, 2011-05-31 at 13:06 -0700, Paul Eggert wrote:
> On 05/31/11 11:12, Shaun Jackman wrote:
>
> > My use case is working in a directory shared amongst a group of users.
> > My umask is 022. I run
> > mkdir -pm775 project/subproject
>
> You're typing stuff like that by hand? I'd expect that sort of
> thing to be in a script. Either way, you can do this instead:
>
> (umask g+w; mkdir -p project/subproject)
>
> This is portable and doesn't require any changes to mkdir.
Hi Paul,
I'm using an alias so that a directory is created with the same
permissions as its parent:
alias mkdir='mkdir -m $(stat -c%a .)'
By hand I'm typing
mkdir -p project/subproject
Your umask suggestion is good. I hadn't thought of changing the umask in
a subshell.
Cheers,
Shaun
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Tue, 31 May 2011 22:22:01 GMT)
Full text and
rfc822 format available.
Message #29 received at 8749 <at> debbugs.gnu.org (full text, mbox):
Shaun Jackman <sjackman <at> bcgsc.ca> writes:
> My use case is working in a directory shared amongst a group of users.
> My umask is 022. I run
> mkdir -pm775 project/subproject
> and I'd like both project and project/subproject to be group-writable.
If the filesystem supports ACLs then you can add a default ACL to the
project directory with `setfacl -m d:g::rwx'. This will arrange to
grant group write access by default to all newly created
files/directories in that directory.
Andreas.
--
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Tue, 31 May 2011 22:50:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 8749 <at> debbugs.gnu.org (full text, mbox):
Shaun Jackman wrote:
> My use case is working in a directory shared amongst a group of users.
> My umask is 022. I run
If you are working among a group of users then you should set your
umask to be 02 instead of 022. That is probably the point where you
diverged from common practice and started to have these problems with
mkdir.
Have you looked at the any of the User Private Group documentation
yet? If not then please do so. Good stuff there.
> mkdir -pm775 project/subproject
> and I'd like both project and project/subproject to be group-writable.
If you set your umask to be 02 then you no longer need to explicitly
set the mode bits to ug=rwx,o=rx anymore.
Bob
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Tue, 31 May 2011 22:57:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 8749 <at> debbugs.gnu.org (full text, mbox):
On Tue, 2011-05-31 at 15:49 -0700, Bob Proulx wrote:
> Shaun Jackman wrote:
> > My use case is working in a directory shared amongst a group of users.
> > My umask is 022. I run
>
> If you are working among a group of users then you should set your
> umask to be 02 instead of 022. That is probably the point where you
> diverged from common practice and started to have these problems with
> mkdir.
>
> Have you looked at the any of the User Private Group documentation
> yet? If not then please do so. Good stuff there.
>
> > mkdir -pm775 project/subproject
> > and I'd like both project and project/subproject to be group-writable.
>
> If you set your umask to be 02 then you no longer need to explicitly
> set the mode bits to ug=rwx,o=rx anymore.
>
> Bob
Hi Bob,
Yes, I have read the documentation on User Private Group. It makes a lot
of sense. Currently all the users of my team are in one group, and so my
umask is 022. I'll have to talk to my systems group about changing our
practice.
Cheers,
Shaun
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Tue, 31 May 2011 23:11:02 GMT)
Full text and
rfc822 format available.
Message #38 received at 8749 <at> debbugs.gnu.org (full text, mbox):
On Tue, 2011-05-31 at 15:49 -0700, Bob Proulx wrote:
> Shaun Jackman wrote:
> > My use case is working in a directory shared amongst a group of users.
> > My umask is 022. I run
>
> If you are working among a group of users then you should set your
> umask to be 02 instead of 022. That is probably the point where you
> diverged from common practice and started to have these problems with
> mkdir.
>
> Have you looked at the any of the User Private Group documentation
> yet? If not then please do so. Good stuff there.
>
> > mkdir -pm775 project/subproject
> > and I'd like both project and project/subproject to be group-writable.
>
> If you set your umask to be 02 then you no longer need to explicitly
> set the mode bits to ug=rwx,o=rx anymore.
>
> Bob
Hi Bob,
It looks like User Private Groups and setgid directories would solve
most of my issues except for one. I'd like directories to be
group-writable (775) by default and files to group-read-only (644) by
default. Andreas suggested using ACL (setfacl -m d:g::rwx), but my file
system sadly does not support ACL. Any suggestions?
I'm using the following alias for directories that are created
interactively:
alias mkdir='mkdir -m $(stat -c%a .)'
Cheers,
Shaun
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8749
; Package
coreutils
.
(Wed, 01 Jun 2011 00:31:01 GMT)
Full text and
rfc822 format available.
Message #41 received at 8749 <at> debbugs.gnu.org (full text, mbox):
Shaun Jackman wrote:
> I was using exactly that shell function that you described, but it
> doesn't work for
> mkdir -p foo/bar
Since we are talking about shell aliases and functions here is a
simple shell snippet that can create the directories with the modes
explicitly.
#!/bin/sh
mkdir_px() {
case $1 in */*) mkdir_px $(dirname "$1") ;; esac
test -d "$1" || mkdir -m $(stat -c %a .) "$1"
}
mkdir_px "$@"
exit $?
It is a little bit long but not unduly so.
> I've noticed one issue, which I feel is a bug in mkdir. When using mkdir
> -pm, the specified mode is applied only to the final directory and not
> the parent directories:
>
> $ mkdir -pm 775 foo/bar
> $ ls -ld foo foo/bar
> drwxr-xr-x 3 sjackman assembly 4096 May 30 10:27 foo
> drwxrwxr-x 2 sjackman assembly 4096 May 30 10:27 foo/bar
>
> I would expect both foo and foo/bar to have mode 775.
That is the original traditional behavior of 'mkdir -p'. As Paul
pointed out in his follow-up that behavior has been in use and is now
standardized by POSIX lest some new implementation decides to do
something different from the previously implemented behavior. It is
unfortunate that it was originally implemented that way but having
done so and gotten into common use it is too late to change it now.
That is why POSIX exists is to prevent the proliferation of different
features on every system when corner case behavior like this is
found. You can pretty much guarentee that someone is counting on that
behavior if for no other reason than just by accident.
Bob
This bug report was last modified 14 years and 78 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.