22

Possible Duplicate:
How to apply recursively chmod directories without affecting files?

What is the command to apply execute permission for directories (for traversal), but leave the execute bit off for files contained in the directory?

m33lky
  • 2,585
  • 1
    There are a lot of questions that deal with this already: http://unix.stackexchange.com/questions/24662/chmod-r-644-documents http://unix.stackexchange.com/questions/1323/i-accidentally-chmod-r-x-on-a-directory-how-do-i-restore-the-correct-permissi http://unix.stackexchange.com/questions/19919/recursively-change-file-permission-but-not-directories, ... – Mat May 31 '12 at 20:04

2 Answers2

48

If you don't want to remove the executable bit from existing files you can use the X mode. To recursively set the executable bit on all directories use:

chmod -R a+X dir

From man chmod:

execute/search only if the file is a directory or already has execute permission for some user (X)

Ulrich Dangel
  • 25,369
4

You want to test this first (as I didn't):

find . -type d -exec chmod u+x {} \;

Find all directories, then add x-bit for the owner/user.

jippie
  • 14,086
  • 3
    If I understand the chmod man page correctly, Ulrich's answer is the better one. – jippie May 31 '12 at 20:09
  • The problem with Ulrich's solution is that to have to specify the directory. The solution by @jippie can be used as a wildcard change. – crafter Jun 01 '17 at 09:43
  • Thank you! It worked for me. I wanted to change only all directories (not files) – Ikrom Nov 27 '18 at 12:48