Recursively chmod only Directories or Files

This particular trick is invaluable, and I’m tired of googling it. You can read the original article here.

[note color=”#DDD”]Directories Only:
find . -type d -exec chmod 755 {} \;[/note] [note color=”#DDD”]Files Only:
find . -type f -exec chmod 644 {} \;[/note] And here are some other ones I found in the comments on the original blog:

[note color=”#DDD”]For files matching a pattern:
find . -type f -name '*.htm*' -exec chmod 644 {} \;[/note] [note color=”#DDD”]According to one commenter, this will work if you’re having trouble with directories or files with spaces in them:
find . -type d -exec chmod 755 \"{}\" \;[/note] [note color=”#DDD”]Supposedly this method runs faster (and solves the problem with spaces):
find . -type d -print0 |xargs -0 chmod 740
find . -type f -print0 |xargs -0 chmod 640[/note]
Category(s): Googling for Answers, Linux
Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy this password:

* Type or paste password here: