Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!ukc!uos-ee!celvin From: celvin@EE.Surrey.Ac.UK (Chris Elvin) Newsgroups: comp.unix.questions Subject: Re: how to compare file modification time in bourne shell script Message-ID: <1990Jul25.124520.5688@EE.Surrey.Ac.UK> Date: 25 Jul 90 12:45:20 GMT References: <1990Jul23.233044.2729@silma.com> Organization: University of Surrey, Guildford, Surrey, UK. GU2 5XH Lines: 32 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 > How's about foobar=`find file2 -newer file1 -print | wc -l` Shell variable foobar will be 1 if file2 is newer than file1 or to answer the question as stated foobar=`find file1 !-newer file2 -print | wc -l` Hope this helps C. -- Chris Elvin C.Elvin@EE.Surrey.Ac.UK "Beware of low flying butterflies!" Dept of Elec. Eng, University of Surrey, Guildford, Surrey, GU2 5XH. England. PHONE: +44 483 509104 FAX: +44 483 34139