This discussion is archived
3 Replies Latest reply: Oct 9, 2012 1:29 PM by EdStevens RSS

I don't understand this behavior of 'find'

EdStevens Guru
Currently Being Moderated
OL 5.6 x86-64

Looking for all files under /u01 that are owned by root

Just showing the setup and the first page of output as returned by the pipe to 'more':
oracle:orcl$ pwd
/u01

oracle:orcl$ ll
total 12
drwxr-xr-x 5 oracle oinstall 4096 Jan 24  2011 app
drwxr-xr-x 2 oracle oinstall 4096 Mar 31  2010 backup
drwxr-xr-x 5 oracle oinstall 4096 Aug 22  2011 oradata

oracle:orcl$ find . -user root -exec ls -l {} \; |more
total 0
total 116
drwxr-x--- 2 oracle oinstall  4096 Dec  3  2009 admin
drwxrwx--- 4 root   oinstall  4096 Dec  3  2009 agent
-rwxr-xr-x 1 oracle oinstall 50550 Feb 13  2011 alertitorcl.log
drwxr-x--- 2 oracle oinstall  4096 Feb  4  2011 client
drwxr-x--- 2 root   oinstall  4096 Dec  3  2009 crsd
drwxr-x--- 2 oracle oinstall  4096 Nov 14  2010 cssd
drwxr-x--- 2 root   oinstall  4096 Dec  3  2009 ctssd
drwxr-x--- 2 oracle oinstall  4096 Dec  3  2009 diskmon
drwxr-x--- 2 oracle oinstall  4096 Feb 13  2011 evmd
drwxr-x--- 2 oracle oinstall  4096 Dec  3  2009 gipcd
drwxr-x--- 2 root   oinstall  4096 Dec  3  2009 gnsd
drwxr-x--- 2 oracle oinstall  4096 Dec  3  2009 gpnpd
drwxr-x--- 2 oracle oinstall  4096 Dec  3  2009 mdnsd
drwxr-x--- 2 oracle oinstall  4096 May 15  2010 ohasd
drwxrwx--- 5 oracle oinstall  4096 Dec  3  2009 racg
drwxr-x--- 2 oracle oinstall  4096 Dec  3  2009 srvm
total 8
drwxrwx--- 2 root oinstall 4096 Dec  3  2009 crsd
drwxrwx--- 5 root oinstall 4096 Dec  3  2009 ohasd
total 12
drwxr-xr-x 2 oracle oinstall 4096 Feb 13  2011 oraagent_oracle
drwxr-xr-x 2 oracle oinstall 4096 Feb  6  2011 oracssdagent_oracle
drwxr-xr-x 2 oracle oinstall 4096 Feb 13  2011 orarootagent_oracle
total 0
total 0
-rw-r----- 1 root root 342 Feb 10  2010 ./app/oracle/product/11.2.0/grid/log/itorcl/client/ocrconfig_22130.log
Notice:
1) except for the last file, (mostly directories) there is no parentage shown
2) even though my spec to 'find' was '-user root' there are several files/dirs that are NOT owned by root.


I'm sure the problem is in my (mis)understanding of some intricacy of 'find' .....
  • 1. Re: I don't understand this behavior of 'find'
    Dude! Guru
    Currently Being Moderated
    The find command in your example is building a list of files before it starts to process the found items. Hence when piping the output through more you get the results you see. You can verify the behavior using strace on the find command.

    Perhaps the following will give you the results you expect:

    <pre>
    find . -user root -ls | more
    </pre>
  • 2. Re: I don't understand this behavior of 'find'
    Nik Expert
    Currently Being Moderated
    Hi.
    Remember that dir is file also.
    ls -l for will show whole content of directory independ of owners.
    So in case root owner of /u01 - this command will show content of this dir.

    In case you need find only files you can use:

    find . -user root -type f - print only file names of this files.

    find . -user root -type f -ls - will show size and additional attributes.

    Regards
  • 3. Re: I don't understand this behavior of 'find'
    EdStevens Guru
    Currently Being Moderated
    Dude wrote:
    The find command in your example is building a list of files before it starts to process the found items. Hence when piping the output through more you get the results you see. You can verify the behavior using strace on the find command.

    Perhaps the following will give you the results you expect:

    <pre>
    find . -user root -ls | more
    </pre>
    Much better. I didn't know you could just tack on an 'ls' (or any other) command without the '-exec ' option.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points