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 644 {} \;

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

---
 
---