I want to change permissions of all 777 folders to 755 and also change all 777 php files to 644.
How can I do this through shell?
P.S: all files and directories are in www directory.
You can change the permissions of all 777 folders to 755 using find as below.
find /var/www -type d -perm 777 -print -exec chmod 755 {} \; The above command will change all the directories inside /var/www to have the permission set as 755. To verify it, you can use the below command.
stat -c "%a %n" /var/www/directory-name To change the permissions of all php files, you can use the below command.
find /var/www/some-directory -type f -name "*.php" -perm 777 -print -exec chmod 644 {} \; Again, you can use the stat command to verify if the permissions had changed. Or you can even use,
ls -ld /var/www/some-directory-name Both stat and ls -ld will display the octal permissions of the file.
-print doing there? "www" could be anywhere on your system, so be more specific next time.
Anyway, I am assuming you meant /var/www:
find /var/www -type d -perm 777 -print0 | xargs chmod 755 find /var/www -name "*.php" -perm 777 -print0 | xargs chmod 644 In the future, refer to man find. It's quite powerful, as you can gather.
-print0 for find and xargs -0 to avoid that. xargs -0 will use null for termination, while -print0 will not echo null in output. -print0 uses null as output separator and -0 tells xargs to use null as input separator.