File Timestamps – How to Check Access Time of a File

fileslinuxtimestampsvi

I am using bash shell. If I just open a file with the vi editor and close it without even moving the cursor even once, then that, as far as I understand, should change the last access time of the file because it has been opened with the editor.

But this did not happen when I experimented this with a file. The last access time remains unchanged in this case. Am I misunderstanding something?

Please clarify the notion of last access time more clearly, and explain how the vi editor is able to access a file without modifying this timestamp.

Best Answer

On Linux, the kernel now mounts file systems with the relatime option enabled by default (see the mount manpage for details), and with this option, access times are only updated if:

  • the previous access time was earlier than the current modification or change time (i.e., the file’s contents or metadata have changed since it was last accessed);
  • or the previous access time is more than a day old.

This reduces the number of disk writes involved in general system usage, while still preserving access information for some programs which rely on it (in particular, certain mail clients), and providing some measure of access time tracking albeit with a very coarse granularity on files which don’t change.

Put another way, on relatime-mounted file systems, the access time is no longer an accurate timestamp, but rather an indicator: it allows you to determine whether a file has been accessed since it was last modified, or if it was accessed within a given period with day-long granularity.

A number of options are available to control this behaviour; see the linked manpage, or man mount on your system, for details.

Related Question