How to Change File and Directory Permissions Recursively in Linux

I recently found that I needed to change a number of directory and file permissions recursively. Simple, you say? Not when the directories and files need different permissions applying.

Change Every Permission

I had managed to get in the unenviable position of having every file and directory with incorrect permissions, and there were too many to go through and change manually.

Normally to recursively change permissions it would simply be a matter of using the -R option. But in this case my directories and needed different permissions setting.

I Wanted a Simple Solution

Most of the solutions that I found were overcomplicated and involved writing a Bash script and looping over lists of files and directories. I thought there must be an easier way.

Luckily after a bit more searching I found this simple solution on Super User. It combines the find command with chmod to accomplish exactly what I needed in just two lines.

An example to recursively give directories read & execute privileges:

find /path/to/base/dir -type d -exec chmod 755 {} +

An example to recursively give files read privileges:

find /path/to/base/dir -type f -exec chmod 644 {} +

Leave a Reply

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