Unix/OS X: CHOWN recursively but selectively

I’m having issues in OS X; for various reasons, a bunch of my Apps are owned by a different Admin user, one I never log in as. Most of the time this is a non-issue; just have to type in a password to monkey with the files. But it’s caused a few problems, and I’d like to get them all on the same page.

However, there are also apps in /Applications which are owned by root. I figure I shouldn’t change those.

So, is there a script I can run that will check to see which files are owned by the old user and only change ownership on those?

chown new_user:new_group find /Applications -user old_user

Thanks! You got me off on the right track. Everything I tried gave me a “too many arguments” error of some variety, but I managed to come up with this beast that worked:

sudo find . -user olduser -print0 | xargs -0 -L100 sudo chown -R newuser

Whew.

I presume you’ve also used the Disk Utility’s “Repair Permissions” feature? It deals with a wide range of these sorts of things without having to go to a command line, although it’s exact behaviour is a little mysterious.

And the command line’s behavior is not mysterious at all. When modifying essential parts of your system, mystery is your enemy.

This is the format I use for all things “find”:

find . [filters] -exec [command] {} ;

Like this:

sudo find . -user olduser -exec chown newuser {} ;

This uses the “-exec” switch of the “find” command. Just put the curly braces wherever you want the individual files found to go in the command string, and remember to put the backslash-semicolon at the end of the command.

The command in “-exec” will be executed once per line produced by “find”