jambino wrote:
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.
Code:
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:
Code:
[dir] DNM 1
|--------- [dir] Subdir
| |
| +-- z ★
+-- a ★
|
+-- b ★
|
+-- c ★
[dir] MODIFYME 2
|
+-- DNM_the_file_unchanged
|
+-- d
|
+-- e
|
+-- f