1751742 Members
5564 Online
108781 Solutions
New Discussion юеВ

Find command help

 
SOLVED
Go to solution
rhansen
Frequent Advisor

Find command help

Hello,

I am using find command to files with unknown UID/GID on HP-UX server. Below is part of the code that I am using:

case "$OSNAME" in
HP-UX) print "Finding unknown files"
find / -path "/var/spool/cron/atjobs" -prune -o \
-path "/dev" -prune -o \
\( -fsonly vxfs -o -fsonly hfs \) \
\( -nouser -o -nogroup \) -print | xargs ls -ls

And I am reading the output
cat /var/adm/issuance/find.log | mailx -s

The problem is the ls -ld is actually doing the ls -ld on the /var/adm/issuance rather than the find command.

Please help!

Thanks.
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Find command help

Hi:

You're making this much harder than it needs to be. I would simply use:

# find / \( -nouser -o -nogroup \) -exec ls -ld {} +

...since most filesystems are VxFS ones anyway. If you like, though:

# find / \( -nouser -o -nogroup \) -a \( -fstype vxfs -o -fstype hfs \) -exec ls -ld {} +

Regards!

...JRF...
rhansen
Frequent Advisor

Re: Find command help

Thanks James.
James R. Ferguson
Acclaimed Contributor

Re: Find command help

Hi (again):

I should add that if you truly want to skip (for example, the '/dev' directory) you could do:

# find / ! -path "/dev/*" \( -nouser -o -nogroup \) -exec ls -ld {} +

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: Find command help

>JRF: I should add that if you truly want to skip you could do:
find / ! -path "/dev/*"

These are not the droids you are looking for. :-)
This doesn't "skip" files but simply doesn't print them.

The correct primary is the hard to understand and poorly documented "-prune", which stops descending the directory tree.
find / -name /dev -prune -o \( -nouser -o -nogroup \) -exec ls -ld {} +

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1276654
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1322635
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1309998
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1303248
James R. Ferguson
Acclaimed Contributor

Re: Find command help

Hi (again):

> Dennis: The correct primary is the hard to understand and poorly documented "-prune",

Yes, that's an understatement :-)

> Dennis: find / -name /dev -prune -o \( -nouser -o -nogroup \) -exec ls -ld {} +

No, this should be a simple, single directory name without leading or embedded slashes:

find / -name dev -prune -o \( -nouser -o -nogroup \) -exec ls -ld {} +

Regards!

...JRF...