Linux recursive chmod only on sub-directories

Go To StackoverFlow.com

9

I'm on linux, and I have a directory with numerous sub-directories and items inside them. I want to run a recursive chmod on all directories and sub-directories but NONE of the files inside those directories.

chmod -R 777 {folder}

Is there a flag I can add to the chmod command to make the chmod only apply to sub-directories?

2012-04-03 21:46
by Sean


19

Off the top of my head:

find {folder} -type d -print0 | xargs -0 chmod 777
2012-04-03 21:49
by Philip Kendall


3

find {folder} -type d -print0 | xargs -0 chmod 777

2012-04-03 21:51
by quodlibetor


2

Try:

find {folder} -type d -exec chmod 777 {} \;

2012-04-03 21:54
by Darren Dempsey
In general, find | xargs will be more efficient than find -exec as xargs will batch together calls to , whereas find -exec will call once for every result. Obviously though there are some situations in which you want a separate call for each result - Philip Kendall 2012-04-03 22:10


2

Straight from the man pages: http://ss64.com/bash/chmod.html

And also corroborated here: https://stackoverflow.com/a/17091831/538512

use the following format or a derivative thereof chmod -R u=rwX,go=rwX {folder}

Hope that helps!

2014-10-16 05:50
by Jared Scott