#!/usr/bin/perl -w # vim: set sw=8 ts=8 si et: # written by: guido socher, copyright: GPL # &help unless($ARGV[0]); &help if ($ARGV[0] eq "-h"); # start in current directory: search_file_in_dir("."); #----------------------- sub help{ print "pff -- perl regexp file finder USAGE: pff [-h] regexp pff searches the current directory and all sub-directories for files that match a given regular expression. The search is always case insensitive. EXAMPLE: search a file that contains the string foo: pff foo search a file that ends in .html: pff \'\\.html\' search a file that starts with the letter \"a\": pff \'^a\' search a file with the name articlehtml: pff \'article.*html\' note the .* instead of just * \n"; exit(0); } #----------------------- sub search_file_in_dir(){ my $dir=shift; my @flist; if (opendir(DIRH,"$dir")){ @flist=readdir(DIRH); closedir DIRH; foreach (@flist){ # ignore . and .. : next if ($_ eq "." || $_ eq ".."); if (/$ARGV[0]/io){ print "$dir/$_\n"; } search_file_in_dir("$dir/$_") if (-d "$dir/$_" && ! -l "$dir/$_"); } }else{ print "ERROR: can not read directory $dir\n"; } } #-----------------------