Numeric File Permissions in Unix
Suppose you are working with a Web server and your task is to make sure that no files or directories have permissions “777″. It would be easy to just recursively change permissions for all files to something like 644, but this may cause unexpected problems. You only need to change those files and directories that have “777″ permission and leave everything else as it is. Here is a simple script that will do just that.
The script will search for files and directories that have “777″ permissions and change files to 644 and directories to 755.
#!/bin/bash find . -type f -exec sh -c ' if [ `stat -c "%a" "{}"` -eq 777 ] then chmod 644 "{}" fi ' \; find . -type d -exec sh -c ' if [ `stat -c "%a" "{}"` -eq 777 ] then chmod 755 "{}" fi ' \;
Popularity: 2% [?]
Related posts:


