How to change the permissions of files in a directory recursively

Smoot Carl-Mitchell smoot at tic.com
Tue Apr 25 00:48:32 UTC 2017


On Mon, 2017-04-24 at 16:53 -0500, Jim wrote:
> On 04/24/2017 02:10 PM, Robert Heller wrote:
> > 
> > At Mon, 24 Apr 2017 13:16:13 -0500 "Ubuntu user technical
> > support,  not for general discussions" <ubuntu-users at lists.ubuntu.c
> > om> wrote:
> > 
> > > 
> > > 
> > > How can I leave the permission of a directory at 755 and change
> > > the
> > > permissions of all of it's files to 766? Everything I have tried
> > > and
> > > what I have found googling ends up setting the dir and file
> > > permissions
> > > the same.
> > Probably suggesting the (obvious/simpleminded) 'chmod -R 766
> > /some/dir'.
> > 
> > > 
> > > 
> > > So if I have /var/www/html/foo/  I want foo to remain at 755 and
> > > files
> > > in foo to change to 766.
> > find /var/www/html/foo/ -type f | xargs chmod 766
> > 
> > (you might need to use sudo on the xargs command and/or the find
> > command,
> > depending on what user your current shell is running under and what
> > the
> > current permissions are.)
> > 
> > Alternitively (for completeness):
> > 
> > chmod -R 766 /var/www/html/foo
> > find /var/www/html/foo/ -type d | xargs chmod 755
> > 
> Robert, thanks for the reply. Earlier it was suggested that I add
> a  * 
> after foo/ and that seems to have worked for me.

For a deep directory you can do:

find <dir> -type f -perm 766

which recursively finds all the regular files and changes their mode in
the directory tree.

Smoot




More information about the ubuntu-users mailing list