This is mainly achieved by searching for files in a date range ...
I used perl to calculate the days from today to a given timestamp, since the GNU date is not available on my system, so -dit is not an option. The code below accepts the date in YYYYDDMM format. See below:
use Time::Local;
my($day, $month, $year) = (localtime)[3,4,5];
$month = sprintf '%02d', $month+1;
$day = sprintf '%02d', $day;
my($currentYear, $currentDM) = ($year+1900, "$day$month");
my $todaysDate = "$currentYear$currentDM";
sub to_epoch {
my ($t) = @_;
my ($y, $d, $m) = ($t =~ /(\d{4})(\d{2})(\d{2})/);
return timelocal(0, 0, 0, $d+0, $m-1, $y-1900);
}
sub diff_days {
my ($t1, $t2) = @_;
return (abs(to_epoch($t2) - to_epoch($t1))) / 86400;
}
print diff_days($todaysDate, $ARGV[0]);
** . Perl, , /. , , Perl
korn script , .
#!/bin/ksh
daysFromToday=$(dateCalc.pl 20110111)
let daysOld=$daysFromToday+31
echo $daysFromToday "\t" $daysOld
find /path/to/dir/ -mtime +$daysFromToday -mtime -$daysOld -type f -ls
+$daysFromToday, , -$daysOld