Setting files and directories to match umask setting recursively

This example of using the find command with chmod might be useful:

https://superuser.com/questions/91935/how-to-chmod-755-all-directories-but-no-file-recursively


Alan's answer above gave me the information I needed to figure this out, but I had to drill down through the comments to find my best solution. The solution I ended up using looked like this:

sudo chmod -R u=rw,g=rw,o=r,a+X /path/to/target

The idea in my case was to have users and groups read and write and others read only. Specifically setting users and groups to rw and others to r effectively removed the 777 permissions I had on pretty much all my files. Then, setting all to X (uppercase X) went back and added execute permission to directories.