Move to the directory you want to start chmodding files in and run the following:
Recursively set FILE permissions.
find . -type f -exec chmod 644 {} \+
Recursively set DIRECTORY permissions.
find . -type d -exec chmod 755 {} \+
*Note, obviously you can change the chmod number to whatever you want, 777, 600, etc.
The way this works is that the chmod command is run once for each file (or directory) that is found by the “find” command. If you use a “+” instead of a “;” at the end of the command, it’ll work more like xargs and run the chmod command once with a big list of files. i.e.
find . -type f -exec chmod 644 {} \+
This should be a lot quicker, if there are many files to process!
Not sure how I missed your comment considering I approved it, but I have updated the post now — thanks!
Yeah, and if we do it this way:
find . -type f -perm 600 -exec chmod 644 {} \+
it sorts out recursively only the files with 600 (rw——-) permissions and sets 644 (rw-r–r–) on those files.
Well… after doing some researches on this topic, I’ve got solution on doing recursive fileperms mods on some files, while skipping it on others (tipically keeping the executable bit on such files). Here it is:
find . -type f -not -perm 755 -exec chmod 644 {} \;
This has the downside that it fails sorting out files with some special permissions like (rwxr-sr-x), which is a special executable belonging to a specific group. An example of such file is the quadrapassel game executable located at /usr/games/quadrapassel on Ubuntu 12.04 Precise (belongs to group “games”).
Furthermore we can do this:
find . -type f -not -perm 755 -not -perm 600 -exec chmod 644 {} \;
to avoid fileperms changes on executables and on strictly owned files (600, or rw——- mode). It sorts out such files, and sets 644 on any others. Of course, the limitation described earlier remains valid (at least for now, but I’ll do further researches on that matter…).
Can someone explain the significance of the trailing \+ at the end of the command?
It took me hours of searching to come up with this solution. Reading the man page for find -exec I kept assuming I could just end it with ” {};”
Can someone explain the syntax of the -exec option?
thanks,
B