1753850 Members
7319 Online
108807 Solutions
New Discussion юеВ

Re: Help Needed on Find

 
yogesh_4
Regular Advisor

Help Needed on Find

Hi all,

I am searching a string using
find /interfaces/eu3/hmsl/italy/it10archive -xdev -exec grep -l 'string' {} \;.

I want to restrict the search only to that particular dir but find command finds the string in /interfaces/eu3/hmsl dir as well.

Is there any alternative to restrict the search for particular dir.

Thanks in advance.

Ta
Yogesh
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: Help Needed on Find

Hi Yogesh:

> Is there any alternative to restrict the search for particular dir.

If you mean not to recursively descend within the starting directory, then:

# cd /desired_path

# find . -type f ! -path "./*/*" -exec grep -l 'string' {} \;

Regards!

...JRF...
Arturo Galbiati
Esteemed Contributor

Re: Help Needed on Find

Hi Yogesh,
find /interfaces/eu3/hmsl/italy/it10archive -xdev -prune -exec grep -l 'string' {} \;

-prune should be your fried in this

HTH,
Art
Dennis Handly
Acclaimed Contributor

Re: Help Needed on Find

find /interfaces/eu3/hmsl/italy/it10archive -xdev -exec grep -l 'string' {} \;

>I want to restrict the search only to that particular dir but find command finds the string in /interfaces/eu3/hmsl dir as well.

I'm not sure how it finds in hmsl, when that directory is the grandparent of the starting directory?

Also you should change "{} \;" to "{} +".
James R. Ferguson
Acclaimed Contributor

Re: Help Needed on Find

Hi (again) Yogesh:

Upon rereading, I noticed that you say that the "...find command finds the string in /interfaces/eu3/hmsl dir as well."

Including the '-type f' as I suggested should eliminate finding symbolic links if that is indeed a problem.

Too, if you do not want to chase symbolic links, add "! -follow" to your 'find' expressions.

Adding '-xdev' is extremely important if/when you do not want to cross mountpoints; most notably if/when you are searching the root ('/') directory.

Regards!

...JRF...