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

last updated in Categories , ,

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.

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

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

$ 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

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"

How to find files by users vivek and wendy

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

Conclusion

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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Notable Replies

  1. Find files owned by root user in “/” directory:
    find / -user root
    find / -group root

Continue the discussion www.nixcraft.com

1 more reply

Participants

Historical Comment Archive

13 comment

  1. 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?

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

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

  2. @chauahan

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

  3. 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

  4. 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

    Have a question? Post it on our forum!