Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

After I apply chmod -R to a directory, permissions are changed for everything within (files and directories). How can I add execute/search (x) permissions to directories without modifying the files?

share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

You can use find.

find ./ -type d -execdir chmod 750 {} +

Where 750 is the mode you'd like to apply and "./" is the directory you will recursively search.

EDIT: Thanks to @Gilles and find(1), I've revised this for additional security and performance.

share|improve this answer
    
@Gilles Thanks, it isn't too frequent that I learn something new about Unix tools :-) That is awesome. Also, now reading the find documentation, one should really use -execdir instead. –  ewindisch Jan 15 '11 at 0:12
add comment

In this particular case you can use X instead of x which only adds the bits to directories or files which already have the executable bit set for some user (i.e. chmod -R +X my_dir).

In general (e.g. if you wanted to make all directories readable without affecting the files), you could either use find with -type d or if you're using zsh (or bash 4 with shopt -s globstar) the **/ glob (both without passing the -R flag to chmod).

share|improve this answer
    
@Gilles: Good point, I've added that to the answer. –  sepp2k Jan 15 '11 at 0:12
    
"use X instead of x which only adds the bits to directories or files which already have the executable bit set for some user" - Thanks! I've missed this thing a lot! –  Ivan Jan 15 '11 at 4:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.