Basically this is accomplished by finding files in a range of dates...
I used perl to calculate the days from today to the given timestamp since GNU date is not available in my system, so -d
is not an option. Code Below accepts date in format YYYYDDMM. See below:
#!/usr/bin/perl
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";
#print $todaysDate;
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]);
**Note: I'm no expert in Perl and this is the very first piece of code I modify/write. Having said that, I'm sure there are better ways to accomplish the above in Perl
Then the below korn script to perform what I needed.
#!/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
I'm finding all files older than +$daysFromToday
, then narrowing the search to days newer than -$daysOld