Retaining file modification times

Martin Weitzel martin at mwtech.UUCP
Thu May 23 11:18:11 AEST 1991


In article <9105211828.AA12327 at fozzie.nrl.navy.mil> phillips at FOZZIE.NRL.NAVY.MIL (Lee Phillips) writes:
>
>I want to do something to a file without changing its modification
>time.  I suppose I can write a script to get the time from ls, do the
>modification, then restore the time (after converting it to numerical
>format) with /usr/5bin/touch, but I'm hoping that there is an easier
>way. (Csh solutions preferred.) 

Not quite what you want, but maybe an idea how to solve this problem
in a general way: Write a C program (let's call it "cmtime") which
stat(2)-s all its arguments (maybe except the first one) and if an
argument is an existing file notes the st_mtime (and eventually st_atime)
together with the file name.

Then "cmtime" fork(2)-s a new process that exec(2)-s the program named
as first command line argument to "cmtime", passing all other command
line arguments. After the child terminates (for which the parent has
waited) the parent resets all the mtime-s to the values noted during the
startup phase.

Incidentally I have written "cmtime" several years ago and hence know
that it's no utterly complicated piece of software. (I don't have the
source on the system from which I'm posting this, otherwise I would have
included it.  If you're in *real* need for the source I could try to fetch
it from the other place.)
-- 
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83



More information about the Comp.unix.shell mailing list