How old is that file?
Tue Nov 2 16:16:41 2004 How old is
Posted by Tony Lawrence
Search Keys: shell
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:
# That's inode change time, stat would be modification, and 8 is access
You'd use this in a script like this:
if [ "$OLD" -gt 20 ]
echo "older than 20 minutes"
You could put the whole script on one line:
printf("%d\n",(time() - (stat(@ARGV)) )/60);
but that's much harder to follow and a lot easier to screw
Got something to add? Send me email.
Increase ad revenue 50-250% with Ezoic
More Articles by Tony Lawrence
Find me on Google+
© 2012-06-17 Tony Lawrence