This is a fairly short post but it's another one of those Note to self things, I've done this 100 times but I can never remember and need to keep looking up again.
Often I want to go through a directory and set all subdirectories to be readable and all the files to be read only by everyone except the owner who should have write permissions as well.1
I've got a little command I use, taken from a thread on stack overflow that was about WordPress but it's very applicable elsewhere.
chown www-data:www-data -R * # Let apache be owner
find . -type d -exec chmod 755 {} \; # Change directory permissions rwxr-xr-x
find . -type f -exec chmod 644 {} \; # Change file permissions rw-r--r--
-
without the execute bit set of files so
chmod -R 755
doesn't work but if you dochmod -R 644
you can't open the directories. ↩