Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to change all file permissions to 644 and all folder permissions to 755 recursively using chmod in the following two situation:

  • If they had 777 permissions
  • Regardless of the permission (with ANY permissions)
share|improve this question
up vote 16 down vote accepted

find . -type d -perm 777 -exec chmod 755 {} \; (for changing the directory permission)

find . -type f -perm 777 -exec chmod 644 {} \; (for changing the file permission)

If they did not have 777 permissions, we easily remove the -perm 777 part.

share|improve this answer
How does this work? What are the curly brackets and backslash for? – Magicode Apr 20 at 11:02

Regardless of the permissions:

chmod -R a=r,a+X,u+w /your/path
share|improve this answer
How does this work? – Magicode Apr 20 at 10:41
sudo find /path/to/someDirectory -type f -print0 | xargs -0 sudo chmod 644


sudo find /path/to/someDirectory -type d -print0 | xargs -0 sudo chmod 755
share|improve this answer
How is this better than the accepted answer? – kasperd Nov 27 '15 at 9:00

Your Answer


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.