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:
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop








![HowTo: Use grep Command In Linux / UNIX [ Examples ]](http://s13.cyberciti.org/images/shared/rp/3/6.jpg)




{ 7 comments… read them below or add one }
Thank you. This article taught something very important today.
Thanks, works well!
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?
Find files in your system which is owned by natasha user & copy all the files on /backup/somefile directory
file_list=`find /home -user natasha -type f`; for file in $file_list; do cp $file /backup/somefile; done;
@chauahan
file_list=`find /home -user natasha -type f`; for file in $file_list; do cp $file /backup/somefile; done;
can anyone suggest who are all accessing my file in unix?