Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.questions Subject: Re: how to compare file modification time in bourne shell script Message-ID: <8855@jpl-devvax.JPL.NASA.GOV> Date: 24 Jul 90 20:24:04 GMT References: <1990Jul23.233044.2729@silma.com> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 28 In article <1990Jul23.233044.2729@silma.com> aab@silma.UUCP () writes: : : I need to compare the modification times of two files in a bourne shell : script. I would like to do this without writing C code. : Machine is Sparcstation 1 running SunOS 4.03c : : Thus I need a function: : : newer file1 file2 : : that returns 0 if file1 is newer than file2 else returns 1 : : Can it be done? Several ways. [ X`find file2 -newer file1 -print` = X ] perl -e 'exit ((stat("file1"))[9] < (stat("file2"))[9])' ls -lt file1 file2 | tail -1 | grep file2 >/dev/null All of these should work on a Sun. Some machines may not have a -newer option to find or a grep that returns a reasonable status. Some really primitive machines don't have Perl. :-) Larry Wall lwall@jpl-devvax.jpl.nasa.gov