![](https://seccdn.libravatar.org/avatar/e8af2e6e8c7f6bc4ac110466a1b9f1aa.jpg?s=120&d=mm&r=g)
On Sun, 24 Mar 2002 14:33:30 +0100
Clayton Cornell
On Sunday 24 March 2002 13:45, zentara wrote:
On Sun, 24 Mar 2002 10:30:56 +0100
Clayton Cornell
wrote: 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 {} \;
OK, this (and the perl script) allows me to look into each file and find each instance of foo in each file. Assume I want to search for filenames... for example all jpegs in a directory tree. Something along the lines of
find *.jpg in /home/user/mydirectory and all subdirs of mydirectory
and have it only return the filenames... something like what dir *.jpg /s would do in DOS.
Ok, that is just a simple use of find find . -name "*.jpg" ;;
Thanks for the perl script BTW... I am starting to teach myself perl, and this will go into my collection.
Yeah, perl is they way to go. Here is another one that finds and then deletes files according to a pattern. You can easily modify it to just find, and not delete. zdel ################################################### #!/usr/bin/perl # Recursively searchs down thru directories for files, with or without ext. # unlinks (deletes) files matching the patterns on commandline # prompts for confirmation before deleting # usage zdel 'pattern'; example '1022', '.bak', '.html.bak' use warnings; use strict; use File::Find; my (@patterns) = @ARGV; if (!defined $ARGV[0]) {print 'Usage: zdel pattern1 pattern2 pattern3 ....',"\n"}; @ARGV = (); find (\&found,"."); $" = "\n"; print "@ARGV\n"; print 'Files selected are listed above. Delete? y/(n) '; if (<STDIN> =~ /^[yY]/){&del} else {exit} print "$#ARGV files deleted\n"; exit; sub found{foreach my $pattern(@patterns){ push @ARGV, $File::Find::name if (($_ =~ /$pattern/) and -f)} } sub del{foreach (@ARGV) { unlink($_) or die "Can't delete $_: $!\n"} } ######################################################### -- $|=1;while(1){print pack("h*",'75861647f302d4560275f6272797f3');sleep(1); for(1..16){for(8,32,8,7){print chr($_);}select(undef,undef,undef,.05);}}