Приглашаем посетить
Ларри (larri.lit-info.ru)

Section 12.13.  Changing Timestamps

Previous
Table of Contents
Next

12.13. Changing Timestamps

In those rare cases when you want to lie to other programs about when a file was most recently modified or accessed, you can use the utime function to fudge the books a bit. The first two arguments give the new access time and modification time, and the remaining arguments are the list of filenames to alter to those timestamps. The times are specified in internal timestamp format (the same type of values returned from the stat function that we mentioned in Chapter 11).

One convenient value to use for the timestamps is "right now," returned in the proper format by the time function. To update all the files in the current directory to look as if they were modified a day ago but accessed now, we could do this:

    my $now = time;
    my $ago = $now - 24 * 60 * 60;  # seconds per day
    utime $now, $ago, glob "*";     # set access to now, mod to a day ago

Nothing stops you from creating a file that is arbitrarily stamped far in the future or past (within the limits of the Unix timestamp values of 1970 to 2038 or whatever your non-Unix system uses until we get 64-bit timestamps). Maybe you could use this to create a directory where you keep your notes for that time travel novel you're writing.

The third timestamp (the ctime value) is always set to "now" whenever anything alters a file, so there's no way to set it (it would have to be reset to "now" after you set it) with the utime function. That's because it's primary purpose is for incremental backups: if the file's ctime is newer than the date on the backup tape, it's time to back it up again.

    Previous
    Table of Contents
    Next