how to compare file modification time in bourne shell script

Chris Elvin celvin at EE.Surrey.Ac.UK
Wed Jul 25 22:45:20 AEST 1990


In article <1990Jul23.233044.2729 at silma.com> aab at 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 at 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



More information about the Comp.unix.questions mailing list