Search for files owned by particular owner and group


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search for files owned by particular owner and group
# 8  
Old 03-09-2018
Quote:
Originally Posted by Soham
No, this does not work because none of the files/sub-directories under current directory is owned by root/other. Some of the files under sub-dirctory are owned by root/other. Consider following

Code:
MY_SERVER:/export/home/sdesai/tools> ls -lrt
total 2
-rwxr-xr-x   1 sdesai   mis           94 Mar  2 08:53 dif
drwxr-xr-x   2 sdesai   mis           96 Mar  9 14:41 sparcs_1
drwxr-xr-x   2 sdesai   mis           96 Mar  9 14:41 sparcs_2
MY_SERVER:/export/home/sdesai/tools> cd sparcs_1
MY_SERVER:/export/home/sdesai/tools/sparcs_1> ls -l
 -rwxrwxrwx  1 oracle  other       1925 Feb 26 04:58 File1.txt
-rwxrwxrwx   1 roor    other       1900 Feb 27 04:58 File2.txt

I want only File2.txt as it is owned by root/other
But you rejected the command that might do that on post #3.

Code:
ls -ld soham/
drwxr-xr-x  4 nobody  nobody  136 Mar  9 13:24 soham/

Code:
$ ls -l soham/
total 0
-rw-r--r--  1 root    staff     0 Mar  9 13:20 file1.txt
-rw-r--r--  1 daemon  operator  0 Mar  9 13:20 file2.txt

Looking for root/staff and displaying only that. Same scenario that you posted.

Code:
$ find . -user root -group staff -exec ls -ld {} +
-rw-r--r--  1 root  staff  0 Mar  9 13:20 ./soham/file1.txt

And I can go a bit deeper

Code:
$ ls -l
total 0
drwxr-xr-x  2 nobody  nobody   68 Mar  9 13:43 dir1
drwxr-xr-x  3 nobody  nobody  102 Mar  9 13:43 dir2
drwxr-xr-x  4 nobody  nobody  136 Mar  9 13:24 soham


Code:
$ find . -user root -group staff -exec ls -ld {} +
drwxr-xr-x  3 root  staff  102 Mar  9 13:44 ./dir2/subdir2
-rw-r--r--  1 root  staff    0 Mar  9 13:44 ./dir2/subdir2/file2.txt
-rw-r--r--  1 root  staff    0 Mar  9 13:20 ./soham/file1.txt

Notice that it did not display dir1 or dir2 but it found that the subdirectory subdir2 matches the request and also that the file ./dir2/subdir2/file2.txt matches the request. No other entries beside what you asked, is showing.

Last edited by Aia; 03-09-2018 at 04:52 PM..
# 9  
Old 03-09-2018
Thanks. It works if you go to that directory and start find command with fine .
But if it is find <dir> (i.e. instead of . give directory name) it does not work. But that's fine.

Thanks to all
# 10  
Old 03-09-2018
Quote:
Originally Posted by Soham
Thanks. It works if you go to that directory and start find command with fine .
But if it is find <dir> (i.e. instead of . give directory name) it does not work. But that's fine.

Thanks to all
It should not make a difference if you give it a dot for this directory or if you are outside of it and you give it the directory that you want to scan.

One outside test:
Code:
find test -user root -group staff -exec ls -ld {} +
drwxr-xr-x  3 root  staff  102 Mar  9 13:44 test/soham/dir2/subdir2
-rw-r--r--  1 root  staff    0 Mar  9 13:44 test/soham/dir2/subdir2/file2.txt
-rw-r--r--  1 root  staff    0 Mar  9 13:20 test/soham/soham/file1.txt

Or absolute path without concern for pwd.
Code:
$ find ~/playground/unix/test -user root -group staff -exec ls -ld {} +
drwxr-xr-x  3 root  staff  102 Mar  9 13:44 /Users/user/playground/unix/test/soham/dir2/subdir2
-rw-r--r--  1 root  staff    0 Mar  9 13:44 /Users/user/playground/unix/test/soham/dir2/subdir2/file2.txt
-rw-r--r--  1 root  staff    0 Mar  9 13:20 /Users/user/playground/unix/test/soham/soham/file1.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files whose owner or group is numeric

I want to add a condition is my find command to include files/sub-directory whose owner or group is all numeric number. My current find command is find . \( -user root -o -user soham\) -type f -exec ls -l {} \; 2>&1 ---------- Post updated at 10:20 AM ---------- Previous update was at... (5 Replies)
Discussion started by: Soham
5 Replies

2. AIX

Files without owner and group

Dears it is normal that the below binaries stay without any owner and group I have checked it in many servers and the like the below /usr/lpp/bos.net/inst_root/etc/ipsec# ls -lrt total 248 -r-xr-xr-x 1 987 987 13589 Jun 29 2005 default_group -r-xr-xr-x ... (5 Replies)
Discussion started by: thecobra151
5 Replies

3. Emergency UNIX and Linux Support

To identify the group owner

If I have to identify the group owner of an AIX group, what is the command to be used. Example: there is an mqadm group, how do I find the owner of this group? Please help. (6 Replies)
Discussion started by: ggayathri
6 Replies

4. UNIX for Dummies Questions & Answers

Finding the Group Owner Name

Hi all, How can i find the group owner name...??? Thanks (4 Replies)
Discussion started by: mansahr143
4 Replies

5. UNIX for Dummies Questions & Answers

Group files by owner and show directory

Hello, i would like to find huge files and group them by owners. To find big files i use this command: ls -lR | sort -bnr +4 | head -n 75 which give me 75 biggest files, then i need to see in which subdirectory is every file. second thing i dont know is how to group those files by owner, could... (6 Replies)
Discussion started by: dealer1985
6 Replies

6. Shell Programming and Scripting

search files with owner having execute permission

Hi All, I have to search for all files in the current directory where the owner having execute operation. I can find the files with specific permission such as 666 find . -type f -perm 666 But how to find files with only execute permission to user. tried with : find . -type f... (3 Replies)
Discussion started by: gotam
3 Replies

7. UNIX for Advanced & Expert Users

How UNIX admin set up this? how files of 744 of other owner can be removed by another owner?

Hi all, We have some files are under 744 permissions and the the owner is say owner1 and group1. Now we have another user owner2 of group2, owner2 can remove files of the owner1 and the permission of those files are 744, unix admin told us he did some config at his side so we can do that. ... (14 Replies)
Discussion started by: TheGunMan
14 Replies

8. Cybersecurity

File owned by oracle user and dba group need readonly access to other users

Under oracle user file abc.txt was created. Oracle user belong to dba group on UNIX Server. However other non Oracle users which belongs to some other network groups need read only access to this file. Every time when I login as other then oracle user and try to view this file it saying that I... (2 Replies)
Discussion started by: groosha
2 Replies

9. Shell Programming and Scripting

permission, owner and group

hello I search a script (ksh for Aix 5.3) to save all permissions, groups and owner for all files. Because we work much to change it, and a mystake ......! So i want execute this script to save/ execute permissions for all files. If you have this script, thank you for your help ;) best... (2 Replies)
Discussion started by: pascalbout
2 Replies

10. UNIX for Dummies Questions & Answers

owner and group in Linux

I am bit unclear of how Linux was set in the real world, please advise me how it's supposed to be. When I log in as root and do a ls -l, I find: /boot, /, /var, /usr, /tmp, /home, /u01, /u02, /u03 and of of this partition is owned by root and the group also belong to root. Is that the way it's... (1 Reply)
Discussion started by: lapnguyen
1 Replies
Login or Register to Ask a Question