find / chmod optimization
Both find and chmod have to read
- all directory entries
- the inodes for all these entries
You probably get a performance improvement by first reading all the entries and then all the inodes (on a rotating disk) because then the disk head does not move between the directory and the inodes). As chmod is stupid (as one of the other answers explains) it should be callescalled through findfind only. But even then it may help to read all the inodes before the first gets written (assuming you have enough free RAM for the disk cache). I suggest this:
find . -printf "" # reading the file names only find . ! -perm 775 -printf "" # reading all the inodes (file names are cached) find . ! -perm 775 -exec chmod 775 + # writing to the cache without reading from disk The good solution: ACLs
The good solution may be completely different: If the files are created in this directory (and not moved from somewhere else) then ACLs can do the job on the fly. You just have to set the default ACLs on the parent directory.
Further improvement may be reached by filesystem optimizations. If it is ext3/ext4 then you may run e2fsck -D from time to time. Maybe it helps to put this directory onto a separate volume. You may try different filesystems or filesystem settings (e.g. different inode sizes).