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.