Associated with each file is a set of three timestamps. These timestamps were discussed briefly when we talked about getting information about a file: the last access time, the last modification time, and the last change time. The first two timestamps can be set to arbitrary values by the
utime function (which corresponds directly to the same-named C library call). Setting these two values automatically sets the third value to the current time, so there's no point in having a way to set the third value.
The values are measured in internal time, namely an integer number of seconds past midnight GMT, January 1, 1970 - a figure that had reached eight-hundred-million-something when this book was being written. (Internally, it's represented as a 32-bit unsigned number, and if we haven't all upgraded to 64-bit machines (or beyond), will overflow sometime well into the next century. We have much more to worry about in the year 2000).
gmtimefunctions work just like C's do: they return the year with 1,900 subtracted. In 2003,
localtimewill give the year as 103.
utime function works like
unlink. It takes a list of filenames and returns the number of files affected. Here's how to make the fred and barney files look as though they were modified sometime in the recent past:
$atime = $mtime = 700_000_000; # a while ago utime($atime,$mtime,"fred","barney")
No "reasonableness" value exists for the timestamps; you can make a file look arbitrarily old or as though it were modified at some time in the distant future (useful if you are writing science fiction stories). For example, using the
time function (which returns the current time as a timestamp), here's how to make the file max_headroom look like it was updated 20 minutes into the future: