I want to change permissions on all folders/files excluding some of them
5,031
(1) The directories:
find . -mindepth 1 -type d -not -name '*.backup' \
-not -path '*.backup/*' -print0 | xargs -0 chmod MODE
(2) The files:
find . -type f -not -name '*.bak' \
-not -path '*.backup/*' -print0 | xargs -0 chmod MODE
For testing you may run the command lines with ls -ld
instead of chmod ...
.
Related videos on Youtube
Author by
mrjayviper
Updated on September 18, 2022Comments
-
mrjayviper almost 2 years
Please refer to the folder hierarchy below.
folder1 -> file11.txt -> file12.txt -> folder11.backup -> file111.txt -> file112.txt -> file113.bak -> folder111 -> and many more folders and files folder2 -> file21.txt -> file22.txt -> file23.bak folder2.backup -> file111.txt -> file112.txt -> folder111 -> folder112 -> file1121.bak -> file1122.txt -> and many more folders and files folder3 -> folder31 -> folder311 -> folder3111.backup -> file3111.txt -> file3112.txt -> folder3111 -> and many more folders and files -> folder3112 -> file31121.bak -> file31121.txt
I want change the ownership (chown) and permissions (chmod) with the following rules:
all folders/subfolders EXCEPT folders that ends in ".backup". In my example folder hierarchy, the following folders and their contents will be ignored: folder11.backup, folder2.backup and folder3111.backup
all files EXCEPT those that has the extension ".bak". But if the file irrespective of its extension is inside a .backup folder, these are excluded because of rule 1.
Thanks for the help. :)
-
Арсений Черенков over 7 yearsyou might use
echo chmod
for testing purpose