Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!axion!vision!chris From: chris@vision.UUCP (Chris Davies) Newsgroups: comp.unix.questions Subject: Re: how to compare file modification time in bourne shell script Message-ID: <1147@vision.UUCP> Date: 26 Jul 90 16:06:00 GMT References: <1990Jul23.233044.2729@silma.com> Reply-To: chris@vision.UUCP (Chris Davies) Organization: VisionWare Ltd., Leeds, UK Lines: 34 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. If you insist... :-) The function returns 0 if file1 is newer than file2. Otherwise it returns 1. Note that there is no check to ensure both files exist. Syntax: newer file1 file2 newer() { F1=$1 F2=$2 echo "$F1\n$F2" > /tmp/newer$$ if ls -t "$F1" "$F2" | cmp -s - /tmp/newer$$ then RS=0 else RS=1 fi rm -f /tmp/newer$$ return $RS } Have fun... Chris -- VISIONWARE LTD | UK: chris@vision.uucp JANET: chris%vision.uucp@ukc 57 Cardigan Lane | US: chris@vware.mn.org OTHER: chris@vision.co.uk LEEDS LS4 2LE | BANGNET: ...{backbone}!ukc!vision!chris England | VOICE: +44 532 788858 FAX: +44 532 304676 -------------- "VisionWare: The home of DOS/UNIX/X integration" --------------