Path: utzoo!attcan!uunet!mcsun!cernvax!chx400!fatcat!acadch!impch!alex From: alex@impch.imp.com (Alex Hanselmann) Newsgroups: comp.unix.questions Subject: Re: how to compare file modification time in bourne shell script Message-ID: <2215@impch.imp.com> Date: 2 Aug 90 13:30:03 GMT References: <1990Jul23.233044.2729@silma.com> Reply-To: alex@impch.imp.com (Alex Hanselmann) Organization: ImproWare ComputerSystems Switzerland Lines: 43 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? yes here's the script for newer. It's work with the modification time. -- #!/bin/sh #newer file1 file2 (mode) # returns 0 if file 1 is newer then file2 refered by mode (A/M/C (=> man ls) # returns 1 if file 2 is newer then file1 refered by mode ... # returns 2 on error if [ $# -lt 2 -o $# -gt 3 ] ;then echo "error in usage: incorrect argc" exit 2 fi NMODE='' if [ $# -eq 3 ] ; then case $3 in [Aa]) NMODE='u' ;; [Cc]) NMODE='c' ;; esac fi [ `ls -t$NMODE $1 $2 | line` = $1 ] && exit 0 exit 1 --- alex