Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!nuug!sigyn.idt.unit.no!sigyn.idt.unit.no!bjornmu From: bjornmu@idt.unit.no (Bj|rn Munch) Newsgroups: comp.unix.questions Subject: Re: how to compare file modification time in bourne shell script Message-ID: <1990Jul24.220136.15795@idt.unit.no> Date: 24 Jul 90 22:01:36 GMT References: <1990Jul23.233044.2729@silma.com> Sender: news@idt.unit.no (Usenet news admin) Organization: Div. of CS & T, Norwegian Institute of Technology Lines: 27 In article <1990Jul23.233044.2729@silma.com>, aab@silma.com (Andy Burgess) 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 |> I needed the same thing once, and did it this way: test `ls -lt file1 file2 | head -1 | grep file1` This will not work if the name file1 is a substring of file2... It really ought to be simpler; after all, ls *has* the information you want, the rest is just needed to translate it. ___________________________________________________________________________ Bj|rn Munch | Div. of Comp. Science & Telematics, bjornmu@idt.unit.no | Norwegian Institute of Technology (NTH), "The Man With a Pipe in His Name" | Trondheim, Norway