0

For my current issue I require listing all the files which have a different owner than the current owner. We have almost 600 000 files in current directory and ls -l or any other ls command will give us trouble.

[system@support forms]$ pwd
/u01/system/reports/foms
[system@support forms]$ ls -ltr|more 
total 22066 
-rwxrwxrwx 1 system sys 94208 Feb 5 2016 UTIL_COGS.rdf 
-rwxrwxrwx 1 system sys 417792 Feb 5 2016 UTIL_AL.rdf 
-rwxrwxrwx 1 system sys 212992 Feb 10 2016 UTIL_PE_BATCH.rdf 
-rwxrwxrwx 1 system sys 311296 Feb 10 2016 UTIL_GF.rdf 
-rwxrwxrwx 1 dev dev 307200 Feb 10 2016 UTIL_NO_ACCT.rdf >>>> this is my Issue 
-rwxrwxrwx 1 system sys 1101824 Feb 10 2016 UTIL_NO_DETAIL_REPORT.rdf 
-rwxrwxrwx 1 dev dev 614400 Feb 16 2016 UTIL_NO301.rdf >>>> this is my Issue 

What do we need to show the files which do not have the expected owner?

James Z
  • 12,209
  • 10
  • 24
  • 44
user2500742
  • 721
  • 1
  • 5
  • 10
  • 1
    Try `ls -ltr | grep -v " ${USER} "`. Option `-v` in grep will do inverse match. – putu May 30 '17 at 05:09
  • Thanks for your update – user2500742 May 30 '17 at 05:29
  • [system@support forms]$ ls -ltr | grep -v "system" total 134 – user2500742 May 30 '17 at 05:29
  • Please let me know if those files can see . If I can see those files so fix those files . Thanks, – user2500742 May 30 '17 at 05:31
  • What do you mean? It didn't list any files belong to other owners? What is the next processing do you want to perform? – putu May 30 '17 at 05:34
  • Yes , it only showing total 134 but not listing anything . – user2500742 May 30 '17 at 05:36
  • The output is different with your question i.e. `total 22066`. Make sure you execute the command in correct directory, and if it doesn't give you any output, probably there are no files having other owners. Try `ls -ltr | grep -v "abcdefg" | tail -n 10`. It should list `latest 10 files which owner is not abcdefg` – putu May 30 '17 at 05:48
  • Yes , executing it from correct directory . Yes that might be case that no other owners . I will check other servers and update if any issues . Thanks a lot for your quick help and time . – user2500742 May 30 '17 at 06:05
  • ls -la should show who the dir is owned by – treyBake May 30 '17 at 15:41

1 Answers1

1

You can use the find command:

 find . ! -user system

It will show all files not owned by system in the current directory.

You can also choose to see recent files: -mtime -10 will show only files modified less than 10 days ago.

 find . -mtime -10 ! -user system

You can also restrict to files only, avoiding to display directories with -type f:

 find . -mtime -10 -type f ! -user system
J. Chomel
  • 8,193
  • 15
  • 41
  • 69