9

I'm on linux, and I have a directory with numerous sub-directories and items inside them. I want to run a recursive chmod on all directories and sub-directories but NONE of the files inside those directories.

chmod -R 777 {folder}

Is there a flag I can add to the chmod command to make the chmod only apply to sub-directories?

legoscia
  • 39,593
  • 22
  • 116
  • 167
Sean
  • 1,110
  • 1
  • 14
  • 24

5 Answers5

19

Off the top of my head:

find {folder} -type d -print0 | xargs -0 chmod 777
vcsjones
  • 138,677
  • 31
  • 291
  • 286
Philip Kendall
  • 4,304
  • 1
  • 23
  • 42
3

find {folder} -type d -print0 | xargs -0 chmod 777

quodlibetor
  • 8,185
  • 4
  • 35
  • 48
2

Try:

find {folder} -type d -exec chmod 777 {} \;

daz
  • 161
  • 2
  • In general, find | xargs will be more efficient than find -exec as xargs will batch together calls to , whereas find -exec will call once for every result. Obviously though there are some situations in which you want a separate call for each result. – Philip Kendall Apr 03 '12 at 22:10
2

Straight from the man pages: http://ss64.com/bash/chmod.html

And also corroborated here: https://stackoverflow.com/a/17091831/538512

use the following format or a derivative thereof chmod -R u=rwX,go=rwX {folder}

Hope that helps!

Community
  • 1
  • 1
Jared Scott
  • 1,045
  • 10
  • 11
0

We can also run below command to change permission of all folders recursively.

sudo chmod 777 -v $(find $PWD -type d)
linux.cnf
  • 519
  • 6
  • 7