How to change bulk folder’s permission Recursively on Linux

Two years back, when I had been worked in hosting company, we had faced lot of issues on daily basis. One time all the wordpress/joomla site’s directory/folder’s permission got changed from 755 to 700 & 775. That time we have used below commands to recover the site one by one. Make sure its very very critical command if you run this command wrongly on home you will be face lots of problem and very critical to revert back. So very carefully while running the command.

For our convenient, I am going to change the “mageshm” user account directory/folder’s permission from 755 to 700 & 775 for testing purpose. To perform this action we need to combine find & chmod commands and do it.

Common Syntax :

The common syntax for bulk directory/folder’s permission change.

Syntax :# find /path/to/folder -type d -perm [Current file permission] -print -exec chmod [Permission need to be change] {} \;

Details :

1) The first argument is the path to folder (Mention your path according that)
2) The second argument is type (If you want to change the folder permission you need to use “d”, for directory use “f”)
3) To check given permission.
4) Print the given permission directory/folder’s.
5) The fifth argument (-exec) change a directory/folder’s permission (-chmod [Permission need to be change]), If anything found by find command.

1) See the directory/folder’s permission of mageshm account.

I have changed the “mageshm” user account directory permission from 755 to 700 & 775 for testing purpose.

  • 5 directory having 700 permission under mageshm account
  • 2 directory having 775 permission under mageshm account
root@2daygeek [/home/mageshm]# ll -h
total 861M
drwx------.  6 mageshm mageshm 4.0K Jan  7 03:41 ./
drwx--x--x. 16 root    root    4.0K Jan  7  2014 ../
-rw-------.  1 mageshm mageshm 1.4K Jan  7 03:18 .bash_history
-rw-r--r--.  1 mageshm mageshm   18 May 11  2012 .bash_logout
-rw-r--r--.  1 mageshm mageshm  176 May 11  2012 .bash_profile
-rw-r--r--.  1 mageshm mageshm  124 May 11  2012 .bashrc
-rw-r--r--.  1 root    root    649M Nov 29 22:39 CentOS-6.5-x86_64-LiveCD.iso
-rw-r--r--.  1 root    root      26 Dec 27 17:55 liks
drwx------.  3 mageshm mageshm 4.0K Dec 31 14:24 links/ (700)
drwx------.  3 mageshm mageshm 4.0K Dec 31 14:28 new/ (700)
drwx------.  2 mageshm mageshm 4.0K Nov 16 15:44 perl5/ (700)
drwx------.  2 mageshm mageshm 4.0K Nov 16 15:37 public_ftp/ (700)
drwx------.  3 mageshm mageshm 4.0K Nov 16 15:37 public_html/ (700)
lrwxrwxrwx.  1 root    root      31 Dec  7 15:11 s-link-file -> /links/soft-link/test-soft-link
lrwxrwxrwx.  1 root    root      38 Dec  7 15:12 s-link-folder -> /links/soft-link/test-soft-link-folder
-rwxr-xr-x.  1 root    root    100M Jan 31  2006 test100.dat*
-rw-r--r--.  1 root    root    101M Dec 30  2012 test100.zip
-rw-r--r--.  1 root    root     12M Dec 30  2012 test10.zip
drwxrwxr-x.  1 root    root      61 Dec 27 19:05 test/ (775)
drwxrwxr-x.  1 root    root      61 Dec 31 14:24 test1/ (775)

2) How to find all the directory with 755 file permission /home/mageshm directory.

Use the below command to find all the directory with 700 permission.

root@2daygeek [~]# find /home/mageshm -type d -perm 700 -print
/home/mageshm/links/
/home/mageshm/new/
/home/mageshm/perl5/
/home/mageshm/public_ftp/
/home/mageshm/public_html/

The above output is showing 5 folders having 700 permission under “/home/mageshm” directory.

3) How to find all the directory with 775 file permission /home/mageshm directory.

Use the below command to find all the directory with 775 permission.

root@2daygeek [~]# find /home/mageshm -type d -perm 775 -print
/home/mageshm/test/
/home/mageshm/test1/

The above output is showing 2 directory having 775 permission under “/home/mageshm” directory.

4) How to change the bulk file permission from 700 to 755.

To perform this action we need to combine find & chmod commands and do it. Like below.

root@2daygeek [~]# find /home/mageshm -type f -perm 700 -print -exec chmod 755 {} \;
/home/mageshm/links/
/home/mageshm/new/
/home/mageshm/perl5/
/home/mageshm/public_ftp/
/home/mageshm/public_html/

Here i’m going to check whether the file permission got changed or not. See the output.

root@2daygeek [~]# find /home/mageshm -type d -perm 700 -print

The above command not showing anything, Its mean none of the directory having 755 permission under “/home/mageshm” directory and their subdirectory.

5) How to change the bulk file permission from 775 to 755.

To perform this action we need to combine find & chmod commands and do it. Like below.

root@2daygeek [~]# find /home/mageshm -type d -perm 775 -print -exec chmod 755 {} \;
/home/mageshm/test/
/home/mageshm/test1/

Here i’m going to check whether the file permission got changed or not. See the output.

root@2daygeek [~]# find /home/mageshm -type d -perm 775 -print

The above command not showing anything, Its mean none of the directory having 775 permission under “/home/mageshm” directory and their subdirectory.

We are preparing all articles in-depth to understand by all level/stage Linux administrators. If the article is useful for you, then please spend less than a minute to share your valuable comments in our commenting section.

Please stay tune with us…Good Luck 🙂

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

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