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

See all GNU/Linux related FAQ
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 a Unix, Linux, *BSD, Apple macOS/OS X operating systems. This page shows how to find all the files owned by a participle user or group when using Linux and Unix-like systems.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux or Unix terminal
Category File Management
OS compatibility BSD Linux macOS Unix
Est. reading time 3 minutes
Advertisement

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

See all UNIX related articles/faq
Let us see how to use the find command to locate all files/folders owned by one or many users on Linux or Unix-like system.

Find file owned by a group

Use the following syntax to find files owned by users(s) in Linux/Unix:
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 all *.mp4 files by group vivek

Run:
$ find $HOME -name "*.mp4" -group vivek
Linux / Unix Find All The Files Owned By a Particular User / Group
To list file in ls command format pass the -ls option to the find:
$ find $HOME -name "*.mp4" -group vivek -ls

Find file owned by user name

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.

Tip: When searching system directory such as / or /var, you must run the find command as the root user.

In this example, locate or find all file belongs to a user called “vivek” in /var directory:
# find /var -user vivek
OR use the sudo command or su command to become the root/admin user:
$ sudo 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"

How to find files by users vivek and wendy

Type:
### match files only ##
# find / -type f -user vivek -o -type f -user wendy
# find / -type f -user vivek -ls -o -type f -user wendy -ls
### match dirs only ##
# find / -type d -user vivek -o -user wendy
# find / -type d -user vivek -o -type d -user wendy
# find / -type d -user vivek -ls -o -type d -user wendy -ls

The -ls will list current file in ls -dils format on the screen.

Finding file NOT owned by a user or group

Pass the -not expr or \! expr as follows:
$ find /dir-to-search -type [f|d] -not -user <user_name> -ls
$ find /dir-to-search -type [f|d] -not -group <group_name> -ls

The following find command will search the entire filesystem (/) for regular files (-type f) that are not owned by the user vivek (-not -user vivek) and list them in Linux or Unix long format (-ls):
# find / -type f -not -user vivek -ls
# find / -type f \! -user vivek -print
# find files that are not owned by group 'vivek' #
# find / -type f -not -group vivek -print
# find / -type f \! -group vivek -print

Summing up

You just learned how to find all of the files created by a particular user/group and display them to the screen. For more info see find command man page using the man command/help command:
$ man find
$ find --help

Also see:

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

18 comments… add one
  • Marcelo Apr 8, 2010 @ 23:16

    Thank you. This article taught something very important today.

  • Anon Jun 28, 2011 @ 0:54

    Thanks, works well!

  • Hemant Jul 5, 2012 @ 6:04

    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 Aug 13, 2012 @ 16:40

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

      • Aman Oct 2, 2012 @ 18:33

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

  • Aman Oct 2, 2012 @ 18:20

    @chauahan

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

  • bhuvana Feb 22, 2013 @ 8:54

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

    • dirtbag Apr 7, 2015 @ 20:46

      @bhuvana.. Its probably Obama.

  • Afsari Oct 15, 2015 @ 18:18

    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

  • Christian Jun 8, 2017 @ 13:20

    Hi,
    How can I search for files that doesnt have a certain owner and create a text list with the owner/ permission and in the right of each file to have a text like File: name of the file, owner, permissions

    Thanks

    • Dan Jul 17, 2020 @ 15:02

      @Christian
      Start with generating the list:
      find /var/log -type f ! -user root

      Then include it into a wrapper to perform the action:
      for file in $(find /var/log -type f ! -user root); do ls -l $file >outputfile ; done
      or
      find /var/log -type f ! -user root -exec ls -l {} >outputfile \;

  • sudheer Mar 1, 2021 @ 9:18

    how to find all files space which is occupied with one user id?

    • 🛡️ Vivek Gite (Author and Admin) Vivek Gite Mar 1, 2021 @ 12:25

      Do you have disk quota enabled? If so

      quota -vs
      quota -vs {userNameHere}

      If disk quota not enabled, then it is going to take shell scripts.

  • CI Feb 10, 2022 @ 9:42

    Thank you. Simple & clear.

  • CF May 3, 2023 @ 19:02

    Your example for getting the files/dirs from 2 users is not correct

    ### match files only ##
    find / -type f -user vivek -o -user wendy
    

    will return all the files owned by vivek and return all the files AND dirs owned by wendy.
    It should be

    ### match files only ##
    find / -type f -user vivek -o -type f -user wendy
    

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.