How to Compare File Date to Current Date

How to Compare File Date to Current Date

Post by Gail Mara Gurm » Fri, 10 Feb 1995 07:54:43



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.

A friend gave me a long and ugly script but I was hoping for something
simpler.

Any ideas?

Thanks in advance.

Gail

--

Parallel Products                 | phone: (510) 922-0194


 
 
 

How to Compare File Date to Current Date

Post by Randal L. Schwar » Sat, 11 Feb 1995 08:14:15


Gail> How can I compare the date of a file to the current date? Actually, I want
Gail> to do something if a particular file is more than an hour old.

Gail> A friend gave me a long and ugly script but I was hoping for something
Gail> simpler.

Try:

        perl -e 'system "something" if -M "a_particular_file" > 1/24'

Reads almost like you said it.

print "Just another Perl hacker,"
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying

Web: <A HREF="http://www.teleport.com/~merlyn/">My Home Page!</A>

 
 
 

How to Compare File Date to Current Date

Post by Michael Pao » Mon, 13 Feb 1995 21:09:11



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 ....
#                               or
#                               -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).
--

 
 
 

1. date/time of a file compare with current date/time

Hi,

I hope i can drop my question about Linux shell programming here?

I'm writing a script in bash to find files. I'm using the slocate
programm, which is being runned every hour using a cron job, to create
it's database.

Now i want to know how long it is ago that the database has been
recreated. Zo i need to check the date and time from that file and
compare it with the current date and time. I know there must be easy to
do but i can't find the trick to do it.

Maikel van Gorkom

Sent via Deja.com http://www.deja.com/
Before you buy.

2. umax scanner

3. how to compare date of file to a fixed date?

4. Win 95, Win 3.1 and Linux sharing the same swap?

5. Archiving files in "date folders" based on date and time file generated

6. ? on compiling new kernel

7. How to compare file date and copy newer file ?

8. Is there a Linux version of Net2Phone?

9. Any utility can replace a label "DATE" in a file with `date output

10. System date and file dates not showing in same time zone

11. perl date conversion for NETSCAPE: bookmark file date format?

12. find files between date x and date y

13. how to get compare the last mod date of files older than 6 months