Tuesday, April 12, 2011

Using "find" to execute a command on files or folders...

The other day I was trying to make all the folders under a directory available for traversing for the owner group (chmod g+rx) but I couldn't get "find" with the "-exec" switch to work. I had installed Eclipse manually and since my umask is 077 it was not letting me access it since root was the owner. I changed the owner group to users and added +r for the group on all files but of course that is not enough for folders. I figured I would use find to get me all the folders and use -exec switch to change the permissions. So I had:

sudo find -type d -exec chmod go+rx '{}'\;

which kept giving me an error message:

find: missing argument to `-exec'

What?! I have all the right arguments, I read the man pages, looked online, tried info looking for samples. It was all there...well not quite, it seems you need to make sure there is a space between the last tick mark (') and the backslash (\).i.e.:

sudo find -type d -exec chmod go+rx '{}' \;