Sure, with the near-magical find command. The simplest way is like this:
find . -user 501 -exec chown Julian {} +
The "find" command is explained in the manpage, and in a number of tutorials and howtos like this one, nut the short idea is "find everything that matches these criteria, and do this command with each one".
.
means to look in (and beneath) the current working directory.
-user 501
means to only find files owned by user 501.
- Note that this is BSD-specific; in some other POSIX systems, user takes a username, and a separate uid flag takes numeric user IDs.
-exec … {} +
means to run whatever's in the "…" (in this case, "chown Julian") repeatedly, passing it as many of the found files as possible.
- So, if there are 5000 files, it may end up calling chown 4 times (on the first 1203, then on the next 1888, and so on).
- Note that this is a BSD extension (although GNU has a similar extension); there is a portable equivalent with
;
instead of +
, but this will call chown once for each file, which will generally take a lot longer. (The standard solution is to use -print0 and pipe the result to xargs -0. But, since you're doing this on a BSD system, you don't have to do that.)
- Note that if you're typing this in the shell, some shells will require you to escape the braces, but bash (the default shell on modern Macs) does not.