How to chmod all folders recursively excluding all folders within a specific folder?
Solution 1
Remove -print
, escape ( and )
and add space after {}
find . -type d \( -path ./node_modules \) -prune -o -exec chmod 644 {} \;
Solution 2
After some playing around, I found that the following worked for me:
chmod
all files recursively excluding files:
find . -not -path "*/node_modules*" -type f -exec chmod 644 {} \;
chmod
all folders recursively excluding folder:
find . -not -path "*/node_modules*" -type d -exec chmod 755 {} \;
Related videos on Youtube
Kraang Prime
BY DAY: Sleeping. BY NIGHT: Coder. FOR FUN: Coder.
Updated on September 18, 2022Comments
-
Kraang Prime over 1 year
I would like to
chmod
all folders and subfolders within a specific folder, except I wish to exclude one folder (and all subfolders it contains).What I have so far is a hack of the following solutions from StackOverflow:
- How to set chmod for a folder and all of its subfolders and files in Linux Ubuntu Terminal?
- Exclude directory from find . command
Here is what I came up with so far:
find . -type d \( -path ./node_modules \) -prune -o -print -exec chmod 644 {}\;
The problem is with or without
-print
I receive the following error :find: missing argument to `-exec'
The following line has the expected results I need
-exec chmod 644{}\;
to read from:find . -type d \( -path ./node_modules \) -prune -o -print
What am I missing on that line to pipe the data to
-exec
? -
Kraang Prime over 7 yearsYour solution worked. Thank you. I was in the middle of writing my solution when you posted this. Accepting as solution and upvoted.
-
help-info.de about 3 yearsWelcome to Super User! Before answering an old question having an accepted answer (look for green ✓) as well as other answers ensure your answer adds something new or is otherwise helpful in relation to them. Here is a guide on How to Answer. There is also tour for the site tour, and help center for the help center.
-
help-info.de about 3 yearsPlease note the conventions for formatting How do I format my posts using Markdown or HTML.