Find files which belong to a user or Unix group

If you need to find all the files owned by a certain Unix user or group in a given directory, it's actually very easy to do using find command.

How to find files owned by a user

If you know the username, this is the command you might use to locate all the files which belong to it:

ubuntu$ find /var -user www-data

In this case, we're looking for all the files and directories owned by a webserver used www-data under /var.

Find files owned by a Unix group

If you're doing a broader search, you may be interested in identifying all the files owned by a Unix group. Here's how you can do it:

ubuntu$ find /usr -group staff

In this example, we're using find to locate all the files in /usr owned by the staff group.

Locate files by UID or GID

If you're more comfortable dealing with Unix user IDs (UIDs) and group IDs (GIDs), you can use them with find command as well. In this example, I'm looking for the temporary files created by myself (my UID on that system is 1000):

ubuntu$ find /var/tmp -uid 1000

I presume this post answers your questions on the topic, but do let me know if there's anything else you'd like me to explain!

See also: