I see a few requests that are similar to mine using the prune action, but what I want to do is recursively navigate through a docroot:
/opt/web
which contains several files and directories:
/opt/web/foo.html (file)
/opt/web/bar.txt (file)
/opt/web/DONOTCHGRP (dir)
/opt/web/assets (dir)
I want to go through the whole docroot and if any files are not group owned by "mygroup" then change the group to "mygroup" and set the group write permission bit, except completely ignore the DONOTCHGRP directory itself and its contents.
I currently have the command to do the chgrp/chmod with no filtering on anything:
find /opt/web -not -group mygroup |
xargs -I {} sh -c '{ chmod g+w {}; chgrp mygroup {};}'
I just can't figure out how to completely skip the DONOTCHGRP directory. Any help will be appreciated.
finddoes that quite well for you with the-pathand-pruneoptions. For example to find all directories except one named/opt/web/DONOTCHGRPunder the/opt/webdirectory:Then simply include your
chmod g+w "$1"; chgrp mygroup "$1";in a shortscriptand make it executable (the<and>above are just for emphasis and not part of the actual command).findwill call thescriptfor all files and directories, except/opt/web/DONOTCHGRPand the files/dirs below it.