×
UNIX.COM Login
Username:
Password:  
Show Password






👤


Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Search for files owned by particular owner and group

👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #8  
Old 03-09-2018
Aia's Unix or Linux Image
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 30 June 2018, 11:27 AM EDT
Posts: 1,715
Thanks: 49
Thanked 663 Times in 619 Posts
Quote:
Originally Posted by Soham View Post
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 03:52 PM..
Sponsored Links
    #9  
Old 03-09-2018
Soham Soham is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 16 July 2018, 11:11 AM EDT
Location: UNIX
Posts: 76
Thanks: 20
Thanked 1 Time in 1 Post
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
Sponsored Links
    #10  
Old 03-09-2018
Aia's Unix or Linux Image
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 30 June 2018, 11:27 AM EDT
Posts: 1,715
Thanks: 49
Thanked 663 Times in 619 Posts
Quote:
Originally Posted by Soham View Post
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

Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Files without owner and group thecobra151 AIX 5 09-10-2014 09:48 AM
Group files by owner and show directory dealer1985 UNIX for Dummies Questions & Answers 6 05-31-2011 04:09 PM
search files with owner having execute permission gotam Shell Programming and Scripting 3 05-06-2010 12:40 PM
How UNIX admin set up this? how files of 744 of other owner can be removed by another owner? TheGunMan UNIX for Advanced & Expert Users 14 01-18-2010 09:04 AM
File owned by oracle user and dba group need readonly access to other users groosha Security 2 09-25-2009 03:41 PM



All times are GMT -4. The time now is 10:01 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.