Is there a shell command for recursively granting rights to directories and files?

Can someone please give me a recursive command that will go through the directory and resolve all regular 644 files and all 755 subdirectories?

I really get tired of doing this manually every time I have to install something on my host. I don't know enough of the BASH command (Shell?) To do this.

+6
command-line bash shell
source share
4 answers

The first line changes the file permissions, and the second changes the directory rights in the active directory and its subdirectories.

find . -type f -print0 | xargs -0 chmod 644 find . -type d -print0 | xargs -0 chmod 755 
+12
source share

There is an option X for this.

 chmod a+X * -R 

This will give the execution bit to directories only, not files. To install 644, 755, respectively, with a single command, use:

 chmod a=rX,u+w <files/dirs> -R 
+15
source share

Using symbolic mode names instead of raw numeric permissions:

 chmod -R u=rwX,go=rX somedir 

The X permission flag sets only directories or already executable files as executable, the -R flag means "recursive" and applies permissions to the entire contents of somedir .

+3
source share

No, there is no command to recursively change permissions. If there was such a command, it would violate the Unix mantra: do one thing and do it well.

However, there are two commands: one for recursion ( find ) and one for changing permissions ( chmod ).

So the magic command line:

 find . -type d -exec chmod 0755 '{}' + -or -type f -exec chmod 0644 '{}' + 
+2
source share

All Articles