Setting chmod/chgrp/chown on multiple files in Linux

This is a handy bit of syntax for updating files and directories on you linux machine where you might have to traverse a number of subdirectories. Use this CAREFULLY! If you are logged in as root you can do untold damage if you accidentally forget to accurately describe your starting path!

As an example, the following will set all directories below and including the present working directory to chmod 755.

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

In the above example, the find command will list all directories in the current directory and below – denoted by ./ -type d. DON’T forget that leading period/full stop!!! Without it you will be affecting all files from the root directory of your system – disaster. You have been warned!

The results are then fed to the -exec option, which executes the chmod 755 command, replacing {} with each directory found. This can be modified in any number of ways.

To modify only files recursively:

find ./ -type f -exec chmod 755 {} \;

To change ownership or group access to files:

find ./ -type f -exec chown username {} \;



No comments yet.

Leave a Reply

Bot test * Time limit is exhausted. Please reload the CAPTCHA.