Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I created a new account in OS X and disposed of my old one.

I have a bunch of files that now have owner 501 that need to have ownership changed to me

[/usr/local]$ ll 
total 24
drwxrwxr-x  18 root  admin   612B Oct 20 11:01 ./
drwxr-xr-x@ 14 root  wheel   476B Oct 19 10:43 ../
-rw-r--r--   1 501   admin   116B Oct 19 10:01 .gitignore
drwxr-xr-x  13 501   admin   442B Oct 19 12:35 Cellar/
drwxr-xr-x   7 501   admin   238B Oct 19 12:17 Library/
-rw-r--r--   1 501   admin   679B Oct 19 10:01 README.md
drwxr-xr-x  42 501   admin   1.4K Oct 20 11:12 bin/
drwxr-xr-x   2 501   admin    68B Oct 20 11:01 cfg/
drwxr-xr-x   5 501   admin   170B Oct 20 11:08 data/
drwxr-xr-x   7 501   admin   238B Oct 20 11:08 docs/
drwxr-xr-x   4 501   admin   136B Oct 19 12:23 etc/
drwxr-xr-x  11 501   admin   374B Oct 19 12:35 include/
drwxr-xr-x  38 501   admin   1.3K Oct 19 12:35 lib/
lrwxr-xr-x   1 root  wheel    27B Oct 20 10:02 mysql -> mysql-5.5.16-osx10.6-x86_64
drwxr-xr-x  16 root  wheel   544B Sep  9 11:08 mysql-5.5.16-osx10.6-x86_64/
drwxr-xr-x  16 501   admin   544B Oct 20 11:01 share/
drwxr-xr-x   4 501   admin   136B Oct 20 11:01 tests/
drwxr-xr-x   2 501   admin    68B Oct 20 11:01 www/



[/usr/local]$ ll Cellar
total 0
drwxr-xr-x  13 501   admin   442B Oct 19 12:35 ./
drwxrwxr-x  18 root  admin   612B Oct 20 11:01 ../
drwxr-xr-x   3 501   admin   102B Oct 19 12:18 gettext/
drwxr-xr-x   3 501   admin   102B Oct 19 12:16 git/
drwxr-xr-x   3 501   admin   102B Oct 19 12:21 glib/
drwxr-xr-x   3 501   admin   102B Oct 19 12:34 gnutls/
drwxr-xr-x   3 501   admin   102B Oct 19 12:23 irssi/
drwxr-xr-x   3 501   admin   102B Oct 19 12:31 libgcrypt/
drwxr-xr-x   3 501   admin   102B Oct 19 12:30 libgpg-error/
drwxr-xr-x   3 501   admin   102B Oct 19 12:20 libiconv/
drwxr-xr-x   3 501   admin   102B Oct 19 12:32 libtasn1/
drwxr-xr-x   3 501   admin   102B Oct 19 12:35 loudmouth/
drwxr-xr-x   3 501   admin   102B Oct 19 12:17 pkg-config/
[/usr/local]$ 

GOAL

I want to recursively find all files and directories in /usr/local/ with owner 501 and chown them to $USER

NOTE

Some of the files and directories in this folder are owned by root. These files need to remain untouched.

share|improve this question

1 Answer 1

up vote 3 down vote accepted
sudo find /usr/local -uid 501 -exec chown $USER '{}' ';'

By the way, find also has the -nouser option that matches all files with UIDs of deleted users:

sudo find /usr/local -nouser -exec chown $USER '{}' ';'

would also match files by another deleted user.

share|improve this answer
    
This worked perfectly :) –  macek Nov 1 '11 at 21:56
    
@phihag @macek A nice chown option is -c which is similar to -v verbose option but only outputs something if the target files actually changes ownership. –  ztank1013 Nov 1 '11 at 22:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.