shell_date_comparison

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



Subject: Re: compare file timestamps in script?
From: Jim Cunning <jcunning@cts.com>
Date: Fri, 28 Jul 2000 15:53:23 -0700 (PDT)

On Fri, 28 Jul 2000, Steve Borho wrote:

> On Fri, Jul 28, 2000 at 11:54:51AM -0500, Bret Hughes wrote:
> > I hate asking questions about what I thought was going to be
> > a simple operation but I cannot find an easy way to compare
> > timestamps of two files.  I felt certain that I sould be
> > able to do this without awking the ls -l outputs but maybe
> > not?  What I want to do is after wget runs, if a particular
> > file's timestamp is newer that the old one I eed to notify
> > someone via mail.  The mail part I can do.  It is timestamp
> > stuff that is escaping me.
> 
> the 'find' command has a -cnewer option that you might find useful.

The simplest way to compare the timestamps of two files is to use a
shell conditional expression with the '-ot' primary. (See "man bash" for
more information.) For example,

	if [ file1 -ot file2 ]; then
	  echo "file1 is older than file2"
	fi

If you want to get more elaborate than simply testing which file is older,
you'll need to use the options in the "find" command.

===

the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu