I want to search in many many files for a string.

I used find /archive/* -print0 | xargs -0 grep 'robert' -sl

Is there a simple method to do it ?

link|improve this question
feedback

migrated from stackoverflow.com May 12 '11 at 11:38

This question came from our site for professional and enthusiast programmers.

2 Answers

The shell expands *. Just omit it, and find will figure out what to do.

find /archive -print0 | xargs -0 grep 'robert' -sl
link|improve this answer
wooow :D:D thx it works – Roby May 12 '11 at 8:55
2  
+1 have a read up on how "globs" work. It's really useful to know. – James C May 12 '11 at 8:56
feedback

There is no need for find. Just use.

grep -m 1 -rsl 'robert' archive/
link|improve this answer
ok, is there any way say, if zou found 100 files its ok and print them out and stop searching more ? – Roby May 12 '11 at 9:22
@Roby grep -rsl 'robert' archive/ | head -100 – Timofey Stolbov May 12 '11 at 9:28
@Timofey: is grep then stopping ? because i had really large files.... like 2mio. – Roby May 12 '11 at 9:30
@Roby Yes of course. – Timofey Stolbov May 12 '11 at 9:35
@Roby: grep -rslm 100 'robert' archive/ – grawity May 12 '11 at 14:16
feedback

Your Answer

 
or
required, but never shown