Search then change owner ship for files/owner

Dung Do
Dung Do used Ask the Experts™
on
I accident deleted one of the accounts on OpenLDAP and now the files/folder in my NFS and Isilon are all messed up. I need to search for folders/files with UID 3015 and change <user> account as owner. The problem is that there are too many files and folders that were changed because the account doesn't exist any more. Is there a script or command I can run to search for folder/files with <ID> then change <user> account as owner

For example:

drwxrwsrws.     3   3015   neuro     28 Dec 19      subject_5002

Need to change 3015 to <user> account
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fractional CTO
Distinguished Expert 2018
Commented:
If I understand what you're asking, like this will work...

find /some-path -uid 3015 -exec chown $user:$group {} \;

Open in new window

nociSoftware Engineer
Distinguished Expert 2018
Commented:
if there are a lot of files it can be significantly faster to use:

find /some-path -uid 3015 -print0 | xargs -0 chown $user:$group

(xargs will tack on files until a command lineis filled or find is ready and then execute very few chown commands.... not one / file.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Best to use noci's suggestion if you have many files, as noci's solution will work for any number of files... 1,000,000s of files, if this is required.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial