Recursively fixing a bad umask

by jenny on 14 April 2012 - 06:04pm in

I usually have a more restrictive umask than the default in my .bashrc:

# Tighten up umask
umask 077

…but every once in a while, I need to open up a directory (and all of its subdirectories and contents). Usually in this situation, I want the directories to have a different set of permissions (say, 755) than the contents (say, 644). Knowing no other way to do this, I’d execute two separate find -exec commands to chmod the directories separately from the normal files.

I guess it was my insistence on using octal chmod arguments rather than letters that allowed one very nice feature of this command to elude me for so long. From man chmod:

…select file mode bits for the affected users: read (r), write (w), execute (or search for directories) (x), execute/search only if the file is a directory or already has execute permission for some user (X)…

Seriously? All this time I never knew there was an X. So to get what I was after, I just needed:

chmod -R go+rX .