Perl - Copy files under 5 mins old
chris (2003-06-30 23:56:09)
Somebody asked me recently to knock up a PERL script which would copy all files in one directory, which were less than 5 mins old, over to another directory. An odd request, but the result involved a nifty use of 'stat' (thanks to Jodrell for the pointer).
my @files=`cd $sourcedir && ls`;
# iterate and copy each one
# get the age in seconds
$age = (time() - (stat($sourcedir.$_)));
print "\n$sourcedir.$_ is is $age seconds old\n";