Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!tut.cis.ohio-state.edu!ukma!uflorida!stat!sun13!VSSERV.SCRI.FSU.EDU!mayne From: mayne@VSSERV.SCRI.FSU.EDU (William (Bill) Mayne) Newsgroups: comp.unix.questions Subject: Re: how to compare file modification time in bourne shell script Summary: Make fooled by symbolic links Message-ID: <324@sun13.scri.fsu.edu> Date: 29 Jul 90 19:32:18 GMT References: <1990Jul23.233044.2729@silma.com> <8855@jpl-devvax.JPL.NASA.GOV> <1990Jul28.151406.11210@onion.pdx.com> Sender: news@sun13.scri.fsu.edu Organization: SCRI, Florida State University Lines: 44 >:> Thus I need a function: >:> >:> newer file1 file2 >:> Others have suggested the use of make to do this, or better yet just use make to do whatever it is that depends upon file seniority. I think this is the most efficient route in terms of using standard unix tools and saving time. But the problem is not as simple as it seems, at least not when using SunOS. (I don't know what other versions of unix share this problem.) What if one of the files being compared is a symbolic link? What modification date and time should be compared? I have been surprised to learn the hard way that the date and time returned by ls and apparently used by make is when the link was created, regardless of the last modification to the actual file. Even if I later edit the file using the alias created by a link rather than the base name it is the base name, not the link, which gets a new modification date and time. I have some program constructions in which I have an awk program generate make files on the fly. Unless I build in enough intelligence for them to track down the base file for each reference I have quite a problem here. My first thought was to write a script which uses to touch to bring the timestamps of links up to date with their base files, but it turns out that touch also passes through to the base file, leaving the link alone. The use of inodes and links described in, for example, "The Unix Programming Environment" seemed so much more straight forward and convenient. As a relative newcomer to unix I am disappointed to find things rather different than what I had expected after reading some of the gurus. The reasons why I can't easily just have all my make files refer to base files rather than links are too complicated to go into here, but I am not just raising theoretical arguments or flames. (I will supply more details if anyone asks.) Others must have faced similar problems. I would be curious to know the reasons why the system behaves in such a surprising way (IMHO), but even more interested to know how others have worked with or around it in this area. Rereading this I see it is long. Just in case my main question gets hidden in the fog, I will restate it: The timestamp of a symbolic link is the time when the link was created, rather than the last modication of the file ultimately referenced. Thus a make file which refers to a symbolic link is fooled. How, short of tracing down all symbolic links when I generate a make file, can I work around this to use the actual modification times of all files or links? Other questions: If I really must trace down the links myself, is there an easy way to do it? Why was the system designed in a way that makes this use of make so difficult?