Recently I found myself needing to reset permissions on a website whose files and folders had been changed to 777. For those who are not familiar with permissions this means all the files and folders are readable but more importantly writeable but anyone. It also makes files executable, or runnable on the server. This could be something you want for upload folders or files you want to be able to edit through a web interface, but not for a whole site. Whatever the reason if the permissions on a folder are messed up this little snippet will reset the permission to the common ones set in a web folder.
chmod -R 0755 directory
cd directory
find ./ -type f -exec chmod 644 {} \;
The first command resets all files and folders to 755, allowing everyone to read and execute (or traverse for directories) and the owner to modify. The third command then resets just files to 644 which drops the allowed to execute flag, turning files from programs into files again.

