O'Reilly logo

Learning Perl, Second Edition by Randal L. Schwartz, Tom Christiansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

13.7. Modifying Timestamps

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 inode-change time. The first two timestamps can be set to arbitrary values by the utime function (which corresponds directly to the same-named UNIX system 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 800-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.[3])

[3] Perl's localtime and gmtime functions work just like C's: they return the year with 1,900 subtracted. In 2003, localtime will give the year as 103.

The utime function works like chmod and 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");

There's no "reasonableness" value for the timestamps: you can make a file ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required