[plug] Bash, File Mtime's (Solved)

Timothy White weirdit at gmail.com
Tue Nov 7 20:30:07 WST 2006


Ok, I'm still going to send it, encase someone else can't work it out.
And I'll give you some solutions.

I wish to check a file's mtime, to see if it's been modified in the last hour.

The dodgy way

touch -d `date -d "1 hour ago"` /tmp/randomfile
[[ file_to_test -nt /tmp/randomfile ]] && do something here

But obviously if there is an easier way, something like...

[[ `date -r file_to_test +%s` -lt `date +%s -d "1 hour ago"`]] && do
something here

There is also the stat command, when you need things like atime, and
ctime etc etc.

So hopefully that'll help someone, and I nearly posted to the list
asking how to do it, totally forgetting about the stat command, then
discovering that the date command also does it!! :D

Tim
-- 
Linux Counter user #273956
Don't email joeblogs at scouts.org.au



More information about the plug mailing list