Operating System - HP-UX
1834696 Members
2182 Online
110069 Solutions
New Discussion

Re: Finding a file .. and not knowing what dir.

 
SOLVED
Go to solution
someone_4
Honored Contributor

Finding a file .. and not knowing what dir.

Hello and good morning.
I have ran into a probelm as always.
How would i go about finding a file in HPUX 11.0 with out knowing what dir it is in. It could be anywhere in the box. So I am looking for a good find command. And to top it off it is not just one name of one file but an ext ..
.cm so i know it would be *.cm
thanks
Richard
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor
Solution

Re: Finding a file .. and not knowing what dir.

Hi Richard:

This is a brute/brutal way:

# find / -name "*.cm"

...JRF...
Pedro Sousa
Honored Contributor

Re: Finding a file .. and not knowing what dir.

Hi Richard.
find / -name *.cm
Alex Glennie
Honored Contributor

Re: Finding a file .. and not knowing what dir.

find / -name *.cm works for me ?
Alex Glennie
Honored Contributor

Re: Finding a file .. and not knowing what dir.

JRF ....

Too slow again doh ! ;)
Bruce Regittko_1
Esteemed Contributor

Re: Finding a file .. and not knowing what dir.

Hi,

find / -name '*.cm' -type f 2> /dev/null

is a good way.

Make sure you quote the *.cm so the shell does not substitute files from the current directory. The -type f will limit the search to regular files. If you are not root, the 2> /dev/null will discard error messages regarding directories you may not search due to a lack of permission.

--Bruce
www.stratech.com/training
Alan Riggs
Honored Contributor

Re: Finding a file .. and not knowing what dir.

Repeat after me: find from / is a bad thing. It is, regretably, sometimes unavoidable, but this is not one of those times.

du -a / | grep "filename$"

Will find your file faster and with far less system overhead.
James R. Ferguson
Acclaimed Contributor

Re: Finding a file .. and not knowing what dir.

Hi Gang:

I personally don't see that 'du' is actually faster than 'find' in the case Alan cites, above.

On a server with only local filesytems, I've compared the execution times by searching the root directory (/) for files named "hosts". The numbers reported are the average of three separate "loops" of the following commands:

# timex find / -name hosts
# timex du -a / | grep "/hosts$"

In each case on my server, four files matched the criteria selected. The times for 'find' where consistently better than for 'du':

> with 'find': r=37.8, u=1.3, s=11.3
> with 'du': r=45.8, u=2,2, s=14.3

...where r=real (elapsed); u=user; s=system...

...JRF...