0

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 ?

2 Answers 2

5

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

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

There is no need for find. Just use.

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

You must log in to answer this question.