 |
Breaking
eBusiness and Search News |
|
 |
How Old Is That File?
Sometimes you want to know the age of a file. Perl has a "-M" test that gives you age in days, but this customer needed it in minutes. That's easy:
#!/usr/bin/perl
# howold.pl
$file=shift @ARGV;
@stat=stat $file;
$now=time();
$mtime=sprintf("%d",($now -$stat[10])/60);
# That's inode change time, stat[9] would be modification, and 8 is access
print "$mtimen";
You'd use this in a script like this:
OLD=`howold.pl myfile`
if [ "$OLD" -gt 20 ]
then
echo "older than 20 minutes"
else
echo "Younger"
fi
You could put the whole script on one line:
printf("%dn",(time() - (stat(@ARGV[0]))[10] )/60);
but that's much harder to follow and a lot easier to screw up.
*Originally published at APLawrence.com Receive
Our Daily Email of Breaking eBusiness News
About the Author:
A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com
WebProNews RSS Feed
More Articles
Contact WebProNews |
|
|
eBUSINESS
RESOURCES |
|
|
 |
|
| About
WebProNews |
WebProNews is the number
one source for eBusiness News. Over 5 million eBusiness professionals read
WebProNews and other iEntry business and tech publications.
WebProNews provides real-time coverage of internet
business.
Free Email Newsletters:
|
|
|
|