#!/usr/local/bin/perl # filemod -- recursively scans the current or specified directory # and returns files in a specified date/time range use File::Find; use Time::Local; use Cwd; sub checkDate { if ( my $date_to_check = shift ) { if ( $date_to_check =~ m/^(\d+)\/(\d+)\/(\d{2,4})\s+(\d+):(\d+):(\d+)$/ ) { my $date = { month => $1 - 1, # Time::Local month starts with zero day => $2, year => $3, hour => $4, minute => $5, second => $6 }; return $date; } } } if ( my $date_after = checkDate( $ARGV[0] ) and my $date_before = checkDate( $ARGV[1] ) ) { my $after_epoch = timelocal( $$date_after{"second"}, $$date_after{"minute"}, $$date_after{"hour"}, $$date_after{"day"}, $$date_after{"month"}, $$date_after{"year"} ); my $before_epoch = timelocal( $$date_before{"second"}, $$date_before{"minute"}, $$date_before{"hour"}, $$date_before{"day"}, $$date_before{"month"}, $$date_before{"year"} ); find( \&isModifiedBetween, $ARGV[2] || getcwd ); sub isModifiedBetween { if (! -d $File::Find::name && -e) { my $file_epoch = (stat $File::Find::name)[9]; if ($file_epoch > $after_epoch and $file_epoch < $before_epoch ) { my $file_time = localtime ($file_epoch); print $file_time."\t".$File::Find::name."\n"; } } } } else { print "invalid token(s): [$ARGV[0]] / [$ARGV[1]]\n"; print "usage: filemod [start date/time] [end date/time] ([directory])\n"; print "date/time format: \"MM/DD/YY HH:MM:SS\" or \"MM/DD/YYYY HH:MM:SS\"\n"; }