bt707
asked on
find oldest file
I have a directory with about 20 sub directories in it that has a thousands of files in them all together, I need a script to find what is the oldest file and show date and time created in which ever one of these sub directories.
EX
/mail/queues/(dir's 1-20)
thanks,
EX
/mail/queues/(dir's 1-20)
thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want to restrict the find to /mail/queues/{1..20} out of possiblly other /mail/queues/* sub directories, other you can use
find(\&process_file, map{"/mail/queues/$_"}1..2 0);
find(\&process_file, map{"/mail/queues/$_"}1..2
ASKER
That one worked great I just didn't get back to accept it, others looks good but the first one worked and didn't get to try the others.
Thanks,
Thanks,
use strict;
use warnings;
use File::Find;
@ARGV = qw(".") unless @ARGV;
my $oldestName = "";
my $oldestDate = 0;
sub process_file {
return unless -f $_ && -M $_ > $oldestDate;
$oldestDate = -M $_ ;
$oldestName = $File::Find::name;
}
find(\&process_file, ".");
my $age = (stat($oldestName))[9];
print "Oldest file is $oldestName. Changed in ", scalar(localtime($age)), "\n";