Recursively change only directory permissions on Linux (Chmod)

by Hemanth on September 7, 2009

Ever wondered how to chmod the  directories recursively  in Linux? I was trying out a PHP script which requires the root directory and  all the sub-directories  under it to be chmodded to full permissions, 777 keeping the existing file permissions intact.

After a bit of searching I found the simple yet powerful solution using the command find.  The following shell command will do the job where /xxx/xxx/xxx indicates the path of the root directory that needs to be recursively chmodded!

find /xxx/xxx/xxx -type d -exec chmod 777 {} \;

The switch -type d ensures that only directories are applied with the chmod command.

It’s clear that find can be used in all kind of batch operations; just specify the required command after the switch -exec.

Update

The commandline -type d can be modified to -type f to change the permissions of all the files instead of directories.

Related Articles:

  • Download Rapidshare files from Linux Shell Command Line
  • List of All DOS Commands
  • Big Google Adsense Change – Modify your ads without changing the code!
  • Big Google Pagerank Crash – Google gone Mad about Link sellers?
  • How to use SSH (Putty) behind a Proxy/Firewall?
  • Leave a Comment