Quote:> How can I compare the date of a file to the current date? Actually, I want
> to do something if a particular file is more than an hour old.
Actually, if your date command supports output formatting, the task
becomes relatively easy. You can use a little manipulation of the TZ
environment variable, along with use of touch and date to create an hour
old file. You can then use the command find with -newer or ! -newer to
test the age of the file, and proceed from there.
Let's see, ... like:
trap "rm -f /tmp/tm$$" 0 1 2 3 15
TZ=GMT0 touch "`TZ=XXX1 date '+%m%d%H%M%y'`" /tmp/tm$$
find "$file" ! -newer /tmp/tm$$ #.... <whatever you want to do with this>
# -print ....
# -exec ...
# or you could do command substitution
# around the find command
Uhm, this will have granularity to the minute, if you can tolerate
that. Also check the format documentation on your date command - your
date may vary (or may not have formatting :-( ), and check the
documentation on your touch command too (some vary).
Also, I use simple TZ variables, with no summer/daylight time, that way,
they'll ALWAYS work, and give you a one hour old file (within 60 seconds
of an hour old, anyway).