Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 ?

share|improve this question

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

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

2 Answers 2

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

find /archive -print0 | xargs -0 grep 'robert' -sl
share|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

There is no need for find. Just use.

grep -m 1 -rsl 'robert' archive/
share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.