2010-01-03, Sun

How to change file or folder permissions recursively with chmod

I needed to change all the php files in a web project to 644 when they were all actually set to 755, and all the folders to 755 when they were set to 700. Here’s how it’s done.

To set all the folders to 755:

    find . -type d -exec chmod 755 {} \;

To set all files to 644:

    find . -type f -exec chmod 644 {} \;

To set only files that end with .php to 755 (pattern escaped with slashes)

    find . -name \*\.php -exec chmod 755 {} \;

You get the idea. Basically, we’re using the find utility to pick out the files we’re wanting to work with, and executing chmod over them.

Isaac Su

tags: bash chmod find linux permissions recursive shell unix

---

Comment

  1. Hey thanks for this post, it helped me :)

    You made a slight typo for changing php file permissions to 755, in that you have written ‘644’.

    — munkychop · Aug 13, 09:29 PM · #

Commenting is closed for this article.

---