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.

link|improve this question
feedback

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

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

2 Answers

up vote 3 down vote accepted

The wildcard * ignores hidden files, but you can explicitly include them with .*:

sudo chmod -R 775 * .*

Or 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 .
link|improve this answer
4  
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
@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
feedback

* 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
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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