1

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:

  1. 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

  2. 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. :)

2

(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 ....

  • you might use echo chmod for testing purpose – Archemar Oct 7 '16 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.