6

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)
22

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.

  • How does this work? What are the curly brackets and backslash for? – Magicode Apr 20 '16 at 11:02
  • Why (??) this is better tham chmod -R a=r,a+X,u+w /your/path ? – Peter Krauss Sep 10 '18 at 0:08
8

Regardless of the permissions:

chmod -R a=r,a+X,u+w /your/path
  • How does this work? – Magicode Apr 20 '16 at 10:41
  • according to man chmod: The letters rwxXst select file mode bits for the affected users: read (r), write (w), execute (or search for directories) (x), execute/search only if the file is a directory or already has execute permission for some user (X) ... – mrossi Jun 19 '17 at 13:44
  • +1, this is way much faster than the accepted answers if you have thousands of files – the_nuts Jun 23 '17 at 16:26
-3
sudo find /path/to/someDirectory -type f -print0 | xargs -0 sudo chmod 644

and

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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