82

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

netic
  • 923
  • 1
  • 7
  • 5

2 Answers2

157

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.

enzotib
  • 92,255
  • 11
  • 164
  • 178
11

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

Steve Bennett
  • 6,497
  • 8
  • 25
  • 28
sagarchalise
  • 23,668
  • 12
  • 72
  • 85