Subject: bug#8749: mkdir: feature request --reference

From: Bob Proulx <[email-masked]>
Date: Sat, 28 May 2011 19:46:52 -0600

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