chmod files only in all subdirectories

Please someone assist me with chmod, I have the following file structure

-dir1 --file1 --file2 --dir1a ---file1a1 ---file1a2 --dir1b ---file1b1 ---file1b2 

How do I chmod 655 to all files under dir1 and all subdir? So all files will have 655 permission and all dir will remain as they were.

Thank you

2 Answers

Better to use

find . -type f -exec chmod 655 -- {} + 

The other proposed solution from @sagarchalise will not work if filenames contain spaces or start with a dash.

5

I think going inside dir1 and

find . -type f | xargs chmod 655

will do the trick.

Or this version, which supports file names with spaces:

find . -type f -print0 | xargs -0 chmod 655

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like