#!/usr/bin/perl -w # delold.pl -- deletes files older than a certain # of minutes use strict; # this is a bit clunky; ideally you'd use the Getopt::Std module, but hey. my $maxage = shift || 15; #you can call the script with "delold.pl 20" and it will delete files that #haven't been modified for 20 minutes. my $dir = shift || "/usr/www/images/temp"; # or wherever makes sense opendir DIR, $dir or die "Can't open $dir: $!\n"; while (my $file = readdir DIR) { next unless -f "$dir/$file"; # skip directories, etc. unlink "$dir/$file" if -M "$dir/$file" > ($maxage / 1440); } closedir DIR;