Find is a very powerful tool in linux which is use to search files and than can perform any specific action on them as per required.
To Find the files having specific permission:
# find /tmp/ -type f -perm 666
> /tmp/ : Its the path of the directory in which you want to search.
> -type f : Here we are searching files only.
> -perm 666 : Searching files having permission 666.
To Find the files having specific name and permission:
# find /tmp/ -type f -name '*.php' -perm 666
> -name '*.php' : Its used to search files with name ending from '.php'.
To exclude any folder from find and change the permission of any specific file:
# find /tmp/ -name "extras" -prune -o -type f -iname '*.cgi' -print -exec chmod 774 {} \;
> -name "extra" -prune -o : It will exclude the "extra" folder from search.
> -iname '*.cgi' : It will search the all files with '.cgi' extension.
> -print : It will print all the files which will be find with '.cgi' extension.
> -exec 774 {}\; : it will change teh permission of all the '.cgi' files found to 774.
To change the permission of all the files and directories under a folder:
# find /tmp/ -type f | xargs chmod 664
> xargs chmod 664 : Changing permission of all the files under /tmp/ to 664
# find . -type d | xargs chmod 755
> xargs chmod 775 : Changing permission of all the directories under /tmp/ to 664
To Find the files having specific permission:
# find /tmp/ -type f -perm 666
> /tmp/ : Its the path of the directory in which you want to search.
> -type f : Here we are searching files only.
> -perm 666 : Searching files having permission 666.
To Find the files having specific name and permission:
# find /tmp/ -type f -name '*.php' -perm 666
> -name '*.php' : Its used to search files with name ending from '.php'.
To exclude any folder from find and change the permission of any specific file:
# find /tmp/ -name "extras" -prune -o -type f -iname '*.cgi' -print -exec chmod 774 {} \;
> -name "extra" -prune -o : It will exclude the "extra" folder from search.
> -iname '*.cgi' : It will search the all files with '.cgi' extension.
> -print : It will print all the files which will be find with '.cgi' extension.
> -exec 774 {}\; : it will change teh permission of all the '.cgi' files found to 774.
To change the permission of all the files and directories under a folder:
# find /tmp/ -type f | xargs chmod 664
> xargs chmod 664 : Changing permission of all the files under /tmp/ to 664
# find . -type d | xargs chmod 755
> xargs chmod 775 : Changing permission of all the directories under /tmp/ to 664