Monday, July 21, 2008

To check the lists of file created between X-Y minutes

I have seen many questions on this ->

how to get a list of files that were created/modified between 30 to 60 minutes? or 1 to 2 hours ... etc.

Here is a simple PERL script to do this job:

use strict;
use File::Find;

my $path_to_start = $ARGV[0];
my @files_bet_30_60 = ();
my $thirty_mins_in_secs = 30*60; # change the value of this var to decrease the lower limit
my $sixty_mins_in_secs = 60*60; # change the value if this var to increase the upper limit

finddepth(\&wanted, $path_to_start);
foreach my $file (@files_bet_30_60) {
print "$file\n";
}

sub wanted {
my $file = $File::Find::name;
next unless (-f $file);

my $mtime = (stat($file))[9];
my $time_diff = time - $mtime;
push @files_bet_30_60, $file if (($time_diff > $thirty_mins_in_secs) && ($time_diff < $sixty_mins_in_secs)); }
Also following shell command can do this:
find /path/to/files -type f \( -newer min60 -a ! -newer min30 \)

0 comments: