I was looking all over for something that could be stuck in a cron job to modify the permissions on any directory in a tree with the words "Do Not Modify" in the name. The idea is that it should make all of the files in those directories read only but preserve the permissions of the Directory itself and anything not in that "Do Not Modify" directory.
I think almost the same may be achieved with a shorter command.
cd /path/to/toplevel/dir && find . -wholename '*DNM*/*' -type f -print0 | xargs -0 chmod a-w
It assumes that any files in directories with DNM
in their names and their subdirectories are to become read-only. Files in other directories (even files with DNM
in their names) will be untouched. As a bonus, this command works also if there are spaces in file names.
This is a small test. I marked with â˜… the files affected by the command:
[dir] DNM 1
|--------- [dir] Subdir
| +-- z â˜…
+-- a â˜…
+-- b â˜…
+-- c â˜…
[dir] MODIFYME 2