![](https://seccdn.libravatar.org/avatar/e8af2e6e8c7f6bc4ac110466a1b9f1aa.jpg?s=120&d=mm&r=g)
On Sun, 24 Mar 2002 10:30:56 +0100
Clayton Cornell
So, I want to search across multiple directories the way 'locate' does, but I don't want to use the database thing that 'locate' uses... I want to pattern match. Can 'find' do this? Is there a better way to do this from the console?
#find files recursively and find foo in them find . -type f -exec grep foo {} \; i#s one way to do it with find. #Some people prefer to use xargs (look at man xargs. find . -type f | grep -v searchstring | xargs egrep; I prefer perl because it allows you more control over customization of the script. Heres one I use: zgrep ############################################################ #!/usr/bin/perl # Recursively searchs down thru directories for pattern in files. # returns directory and line numbers too, and only searches text files. # usage zgrep 'search pattern' 'ext'(optional with no .) use warnings; use strict; use File::Find; my ($search, $ext) = @ARGV; if (defined $ext) {$ext = ".$ext"} else {$ext = '.*'}; die "Usage : greprz 'search' 'extension' (extension optional)\n" if ($search eq ""); @ARGV = (); find (sub { push @ARGV, $File::Find::name if (-f and -T and $ext or /\Q$ext$/)}, "."); while (<ARGV>) { close ARGV if eof; print "$ARGV: $. :$_\n" if /$search/; } ############################################################# $|=1;while(1){print pack("h*",'75861647f302d4560275f6272797f3');sleep(1); for(1..16){for(8,32,8,7){print chr($_);}select(undef,undef,undef,.05);}}