Subject: Re: bug#8729: RFE: chmod "-D" operate on dir's only

From: Eric Blake <[email-masked]>
Date: Wed, 25 May 2011 07:54:08 -0600

On 05/24/2011 07:57 PM, Linda Walsh wrote:
> I know one can (and I usually do) construct a find command to do
> this, but it's something I do so often, and it's a natural 'pair'
> for what is often done with chmod.
> 
> If I want to make sure a dir tree is readable/accessable
> by a group or other, I usually do:
> 
>  chmod -R g+r,o+r .
>  find . -type d -print0|xargs -0 chmod g+x,o+x
> 
> What'd be a great addition to chmod is for it to have an option
> for chmod to only work on dirs.  (is -D taken?)
> 
> So instead of the 2nd line above:
> 
>  chmod -DR g+x,o+x
> 
> ----
> What'cha think?

I think that you are better off using what POSIX has already
standardized for chmod:

chmod -R go+rX .

which says for all files in the hierarchy, add read bits for group and
others to files and directories, and add execute bits only for files and
directories that were already executable by the user.  Thus
non-executable files (since your directories likely already have the u+x
permission, since a non-searchable directory is rare) are not granted
execute permissions, while directories are nicely handled without
needing a followup find|xargs.

> 
> Is that a useful and logical addition for chmod?

It's not a very strong case, and certainly not strong enough to burn a
short option letter for.  But if you want to pursue the idea, a patch
with a long option name (instead of short option), documentation, and
test cases, as well as rationale why relying on already standardized
tools is inefficient, may sway my mind.

-- 
Eric Blake   [email-masked]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org