≡ Menu

Linux / Unix: Find All The Files Owned By a Particular User / Group

How do I list or find all the files owned by a particular system user or group under Linux or UNIX like operating systems using command line options?

You need to use the find command to search for files in a directory hierarchy. It has options that allow you to search files owned by a specific user or groups under Unix / Linux / *BSD / Apple OS X operating systems.

Find file owned by a group

Use the following syntax:


find directory-location -group {group-name} -name {file-name}

Where,

  • directory-location : Locate the file in this directory path.
  • -group {group-name} : Find the file belongs to group-name.
  • -name {file-name} : The file name or a search pattern

In this example, locate or find all files belongs to a group called “ftpusers” in the /home directory:
# find /home -group ftpusers
To find all *.c file belongs to a group called “ftpusers” in /data/project directory, run:
# find /data/project -group ftpusers -name "*.c"
OR do case insensitive search:
# find /data/project -group ftpusers -iname "*.c"

Find file owned by user

The syntax is:

find directory-location -user {username} -name {file-name}

Where,

  • directory-location : Locate files or directories in this directory location.
  • -user { user-name } : Find the file belongs to user.
  • -name {file-name} : File name or pattern.

In this example, locate or find all file belongs to a user called “vivek” in /var directory:
# find /var -user vivek
To find all *.pl (perl files) file belongs to a user called “vivek” in /var/www directory, enter:
# find /var/www -user vivek -name "*.pl"

See also:
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 9 comments… add one }
  • Marcelo April 8, 2010, 11:16 pm

    Thank you. This article taught something very important today.

  • Anon June 28, 2011, 12:54 am

    Thanks, works well!

  • Hemant July 5, 2012, 6:04 am

    I tried …
    root:suraj> find /var -user hemantr
    /var/spool/mail/hemantr
    /
    root> find / -user hemantr
    ^C/
    root> find /u -user hemantr
    /
    root> find /u/hemant -user hemantr
    find: 0652-019 The status on /u/hemant is not valid.
    /
    root> find /var -id 351
    find: 0652-017 -id is not a valid option.
    /
    Please can you let me know how to find files using id?

    • chauahan August 13, 2012, 4:40 pm

      Find files in your system which is owned by natasha user & copy all the files on /backup/somefile directory

      • Aman October 2, 2012, 6:33 pm

        file_list=`find /home -user natasha -type f`; for file in $file_list; do cp $file /backup/somefile; done;

  • Aman October 2, 2012, 6:20 pm

    @chauahan

    file_list=`find /home -user natasha -type f`; for file in $file_list; do cp $file /backup/somefile; done;

  • bhuvana February 22, 2013, 8:54 am

    can anyone suggest who are all accessing my file in unix?

    • dirtbag April 7, 2015, 8:46 pm

      @bhuvana.. Its probably Obama.

  • Afsari October 15, 2015, 6:18 pm

    find / -user afsari -exec cp -pfr {} /afsari_user_file \;

    syntax: Example: find
    “/” like search directory
    “-exec” execute
    “cp” copy
    “/afsari_user_file” copy directory
    “\” loop at the end

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , , , ,