How to chmod the files based on the results from find command

Think about your requirement for a moment.  Do you (might you possibly) have any executable files (scripts or binaries) in your directory tree?  If so, do you want to remove execute permission (even from yourself), or do you want to leave execute permission untouched?  If you want to leave execute permission untouched, you should use chmod o-w to remove (subtract) write permission from the others field only.

Also, as Anthon points out, the find command given in the other answer executes the chmod program once for each world-writable file it finds.  It is slightly more efficient to say

find  top-level_directory  -perm -2  -type f  -exec chmod o-w {} +

This executes chmod with many files at once, minimizing the number of execs.

P.S. You don’t need the leading zeros on the 2.


find /dir/stuct/path -perm -0002 -type f -exec chmod 664 {} \;

The "{}" represents the file found by find. The "\;" ends the command that needs to be executed.