linux-l: AW: linux-l: Über ganze Verzeichnisse gre?==?iso-8859-1?Q?pen

Andreas Kotes count at linux.de
Do Okt 22 09:11:29 CEST 1998


Hi Hartmut :)

On Thu, 22 Oct 1998, Vogler, Hartmut wrote:

> > > > > Ich sehe mal wieder den Wald vor lauter Bäumen nicht, wie kann ich über
> > > > > mehr als ein Verzeichnis grepen?
> > > > > 
> > > > > grep suchmuster *
> > > > > 
> > > > > sucht ja nur im eigenen Verzeichnis. Meine bisherigen Konstruktionenmit
> > > > > */*/* nerven, weil ich vorher immer die maximale Verzeichnistiefe
> > > > > wissen muß.
> > > > > Ich finde auch kein Parameter zum rekursiv grepen, oder ist das ein
> > > > > Shell-Problem?
> > > > > Mit find -name datei * wird rekursiv ausgehend vom Standort alles
> > > > > gefilzt.
> > > > 
> > > > grep /wo/du/suchen/willst/ -exec grep suchbegriff {} \;
> > > 
> > > Ich Idiot! Es muß heißen:
> > > 
> > > find /wo/du/suchen/willst -exec grep suchbegriff [} \;
> > 
> > *aua* .. dann wird fuer jedes dumme file ein prozess gestartet ...
> > 
> > besser (wie gesagt)
> > 
> > find /wo/du/suchen/willst -type f | xargs grep blafasel
> > 
> HaHa ?!
> Hier wird wohl nicht für jedes File ein Prozess gestartet ... ich denke wohl !

da denkst du falsch ;)

bei der oberen loesung ist es klar ersichtlich das fuer jedes file ein
grep gestartet ist, im zweiten fall verweis ich mal auf xargs(1):

"[..]xargs  reads  arguments from the standard input, delimited by blanks
(which can be protected with  double  or  single quotes  or a backslash)
or newlines, and executes the command (default is /bin/echo) one or
more  times  with  any initial-arguments followed by arguments read from
standard input.  Blank lines on the standard input are ignored.[..]

--max-args=max-args, -n max-args
   Use  at  most  max-args arguments per command line. Fewer than
   max-args arguments will be used  if  the size (see the -s option) is
   exceeded, unless the -x option is given, in which case xargs will
   exit.
[..]
--max-chars=max-chars, -s max-chars
   Use  at most max-chars characters per command line, including the
   command and initial arguments and the terminating  nulls  at  the
   ends  of  the argument strings.  The default is as large as  possible,
   up to 80k characters."

Ergo: es werden einem grep soviele argumente (sprich: dateien)
gleichzeitig zum durchsuchen uebergeben wie in eine 80k commandline
passen.

btw ist mir eingefallen das man das fuer manche faelle noch extenden muss:

find /wo/man/will -type f | sed -e "s/^/\"/" | sed -e "s/$/\"/" | xargs grep blafasel 

Gruss

  der Count

--
Andreas Kotes - mailto:count at linux.de - If you need any help, just ask!
    -= "Free speech not only lives, it rocks!" --Oprah Winfrey -=-
-= Commercial use of my email adress NOT allowed. PGP key available. =-   




Mehr Informationen über die Mailingliste linux-l