[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: wish: chmod -R to handle directories and files differently
From: |
Eric Blake |
Subject: |
Re: wish: chmod -R to handle directories and files differently |
Date: |
Tue, 15 Apr 2014 05:57:48 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 |
On 04/15/2014 05:43 AM, Richard Neill wrote:
> Dear All,
>
> May I suggest an enhancement to chmod? The problem is that, when using
> chmod -R, the permissions we want to apply to files are usually not the
> same as for directories, especially regarding the executable state.
chmod already has such a feature via the X symbolic mode - you just need
to use it.
> Here are a few ideas for how this could work...
>
> 1.
> Add a "-d" option that specifies a different permission for directories.
> Eg:
> chmod -R 644 -d 755 path/to/dir
> #This sets everything to 644 (as normal for chmod), but treats
> #directories specially, setting them to 755.
chmod -R u+w,a+rX path/to/dir
give the user write bits, and give all (user, group, and other) the read
bit and conditional executable bit
>
>
> 2.
> Add a "-u" option for using the umask. E.g:
> chmod -R -u path/to/dir
> #This applies my standard umask, for both files and dirs. It would be
> #useful for fixing up broken permissions quickly.
chmod -R +rwx path/to/dir
by omitting anything left of the +, this says to use the umask to grant
all permissions allowed by the umask
>
>
> 3.
> Add "-D" and -"F" options to mean "apply to directories only" or "apply
> to files only"
> E.g.:
> chmod -RD 755 /path/to/dir
> recursively sets directories 755, (and leaves files unaltered).
> chmod -RF 644 /path/to/dir
> recursively sets files to 644, (and leaves directories unaltered).
Here, I'd recommend that you use 'find' rather than bloating chmod further:
find . \( -type d -exec chmod 755 {} + \) -o \( ! -type d -exec chmod
644 {} + \)
>
>
> Typical use-cases:
>
> (a) I have several nested directories of photos that originated from a
> digital camera with a FAT filesystem. Therefore all the directories,
> subdirectories and files are mode 777. I want to remove the executable
> permission from the files, but not the directories.
>
> => chmod -Ru my/photos/
>
> (alternative is some ugliness with "find -type d")
Ugly but standardized and universally existing is better than pretty but
unimplemented on the majority of systems.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature