##!/usr/local/bin/perl eval "exec perl -S $0 $*" if $running_under_some_shell; # # Go through document and find as many violations as possible. # # Matthias: 13Oct94 # $usage = "Usage: $0 [-i] [-j] [-z] [-o] [-v] dir\n"; $selfdoc = " finds potentially superfluous files in a subdirectory tree dir. [-i] flag lets the user remove files interactively. [-j] files with names indicating junk files [-z] finds files of zero size [-o] finds files not used for years [-v] finds files ending with a date, such as filename.31Feb89 See also: Execstat Figstat Wastestat Tour Grepper\n"; if( $#ARGV < 0 ||$#ARGV > 5 ) { print $usage; die $selfdoc; } while($ARGV[0]) { $_ = shift; SWITCH: { if (/^-i/) { $interact = "yes"; last SWITCH; } if (/^-j/) { $junkfile = "yes"; last SWITCH; } if (/^-z/) { $zerofile = "yes"; last SWITCH; } if (/^-o/) { $voldfile = "yes"; last SWITCH; } if (/^-v/) { $versions = "yes"; last SWITCH; } if ( -d $_ ) {$dir = $_ ; last SWITCH; } $nothing = 1; } } #if there is no search criteria specified then use them all if ($junkfile eq "" && $zerofile eq "" && $voldfile eq "" && $versions eq "") { $junkfile = "yes"; $zerofile = "yes"; $voldfile = "yes"; $versions = "yes"; } if ($dir eq "") { print "here1\n"; die "$usage\n"; } chdir $dir; open(FIND, "find . -print |") || die "Could not run find: $!\n"; FILE: while($filename = ) { chop $filename; if ( -d $filename) { if ($filename =~ /\S*\.old\b/) { &act($filename,$interact);} next FILE ; } if ($junkfile eq "yes") { &junkcheck($filename,$interact); } if ($zerofile eq "yes") { &zerocheck($filename,$interact); } if ($voldfile eq "yes") { &voldcheck($filename,$interact); } if ($versions eq "yes") { &verscheck($filename,$interact); } next; } sub junkcheck{ local($file,$iflag) = @_; $fname = $file; $fname =~ s/^.*\///g; # print "$fname \n"; COND: { if ($fname =~ /\S*junk\S*/) { &act($file,$iflag);last COND;} if ($fname =~ /\S*\.old$/) { &act($file,$iflag);last COND;} if ($fname =~ /\S*\.ER$/) { &act($file,$iflag);last COND;} if ($fname =~ /\S*\.CR$/) { &act($file,$iflag);last COND;} if ($fname =~ /\S*\.NR$/) { &act($file,$iflag);last COND;} if ($fname =~ /\S*\.aux$/) { &act($file,$iflag);last COND;} if ($fname =~ /\S*\.bbl$/) { &act($file,$iflag);last COND;} if ($fname =~ /\S*\.o$/) { &act($file,$iflag);last COND;} if ($fname =~ /\S*\.x$/) { &act($file,$iflag);last COND;} if ($fname =~ /\S*~$/) { &act($file,$iflag);last COND;} if ($fname =~ /\b#\S*\#$/) { &act($file,$iflag);last COND;} if ($fname =~ /\bfoo\S*/) { &act($file,$iflag);last COND;} if ($fname =~ /\ba\.out$/) { &act($file,$iflag);last COND;} if ($fname =~ /\bcore$/) { &act($file,$iflag);last COND;} $nothing = 1; } } sub zerocheck{ local($file,$iflag) = @_; # print "$file \n"; COND: { if ( -z $file && $file ne "YMTRANS.TBL" ) { &act($file,$iflag);last COND; } $nothing = 1; } } sub voldcheck{ local($file,$iflag) = @_; # print "$file \n"; COND: { if ( -M $file > 1000 ) { &act($file,$iflag);last COND;} if ( -A $file > 365 ) { &act($file,$iflag);last COND;} $nothing = 1; } } sub verscheck{ local($file,$iflag) = @_; # print "$file \n"; COND: { if ($file =~ /\S*\95\b/) { &act($file,$iflag);last COND;} if ($file =~ /\S*\94\b/) { &act($file,$iflag);last COND;} if ($file =~ /\S*\93\b/) { &act($file,$iflag);last COND;} if ($file =~ /\S*\92\b/) { &act($file,$iflag);last COND;} if ($file =~ /\S*\91\b/) { &act($file,$iflag);last COND;} if ($file =~ /\S*\90\b/) { &act($file,$iflag);last COND;} if ($file =~ /\S*\89\b/) { &act($file,$iflag);last COND;} if ($file =~ /\S*\88\b/) { &act($file,$iflag);last COND;} if ($file =~ /\S*\87\b/) { &act($file,$iflag);last COND;} $nothing = 1; } } sub act{ local($file,$iflag) = @_; if ($iflag eq "yes") { print "/bin/rm -r $file\n"; } else { print "$file\n"; } }