Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I recursively execute chmod or chown for hidden files?

sudo chmod -R 775 * does not work on hidden files.

The same thing goes for sudo chown -R user:group.

share|improve this question

migrated from stackoverflow.com Oct 12 '11 at 13:12

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 15 down vote accepted

If you're okay also chmod'ing the current directory, do that and let -R do the heavy lifting. -R does not ignore hidden files.

sudo chmod -R 775 .
share|improve this answer
10  
This (* .*) is not the safest way to do it. Particularly, it would recurse into parent directory, which means it chmods also siblings of the current directory. The proper way would be * ..?* .[^.]* or, even better (considering the wildcards might not match any files) $(ls -A). –  jpalecek Oct 12 '11 at 13:34
1  
@jpalecek: The output of ls is unparseable; trying to parse it is asking for trouble. The proper approach is to use shell globbing. –  Scott Severance Dec 11 '11 at 17:58
    
@JulianKnight I've stricken out the bad answer. Sorry all for the bad advice. I never saw jpalacek's comment, and I can't delete this answer since it's been accepted. –  John Kugelman Mar 21 '13 at 21:46
    
Well done @JohnKugelman. –  Julian Knight Mar 21 '13 at 21:48

* doesn't include hidden files by default, but if you're in bash, you can do this with:

shopt -s dotglob

Read more about it in bash's builtin manual:

If set, Bash includes filenames beginning with a `.' in the results of filename expansion.

This will make * include hidden files too.

chmod -R 775 *

Disable it with:

shopt -u dotglob
share|improve this answer

Another option is to use find i like it since you can have very fine grained control over it.

find <path to start from> -exec chown <options> {} \+

find -path '<path to include>' -exec chown <options> {} \+

The only downside is that find has different syntax on different versions.

share|improve this answer

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.