4

After using the cat command to read a file, I used the stat command to view it's changed access time, but it's not getting updated.

I checked /etc/fstab file and there is no noatime on any of my drives, so why is the access time not getting updated?

I'm using Ubuntu 12.04 Precise Pangolin.

  • Please post the output of grep /the/mount/point/where/you're/seeing/that/ /proc/mounts. – Mat Dec 8 '13 at 12:12
5

Instead of cat you must use touch (or something that force a write), or explicitly declaring atime in your mount option.


Ubuntu uses relatime as default. The Linux kernel, in fact, uses relatime as the default from version 2.6.30 onwards. This only updates certain values when files are accessed instead of all. This modifies the cat behavior so it won't update the access time. This is the default in Ubuntu mount options. The only way to modify the access time is touching the file (aka forcing a write) instead of a simple read.

The reason behind this is the performance. If each read requires a write as the POSIX requires, the efficiency of disks and flash based devices will be worse. This also seems counter producent in read-only filesystems.

There's a bunch of discussion about this topic in Ask Ubuntu and Super User:

  • how can i enable atime, just for curiosity . I am running a test server on my home so i just want to test things – Cody Dec 8 '13 at 14:23
  • @Cody mount the filesystem with atime. – Braiam Dec 8 '13 at 14:38
  • Now I got it. It only updates file access time when is earlier than modify time or change time. – Cody Dec 8 '13 at 14:38
  • and How can i do that ?? – Cody Dec 8 '13 at 14:40
  • @Cody I think that's is asked somewhere else several times. Try change linux mount options. – Braiam Dec 8 '13 at 14:42
3

There are 3 mount options that you generally have to be aware of when dealing with atime. You're familiar with the first 2, from mount's man page

excerpts

atime  Do not use noatime feature, then the inode access time is controlled 
       by kernel defaults. See also the description for strictatime and  
       relatime mount options.

noatime
          Do not update inode access times on this filesystem (e.g., for 
          faster access on the news spool to speed up news servers).

The other option you're likely not familiar with, and the one causing your grief is this one, which has been the default since kernel 2.6.30:

relatime
          Update  inode  access times relative to modify or change time.
          Access time is only updated if the previous access time was 
          earlier than the current modify or change time. (Similar to 
          noatime, but doesn't break mutt or other applications that need to 
          know if a file has  been  read since the last time it was 
          modified.)

          Since  Linux 2.6.30, the kernel defaults to the behavior provided 
          by this option (unless noatime was  specified), and the 
          strictatime option is required to obtain traditional semantics. In 
          addition, since Linux 2.6.30, the file's last access time is 
          always   updated   if   it   is more than 1 day old.

You can check if these options are set on a filesystem by looking under /proc/mounts.

Example

$ cat /proc/mounts  | head -5
rootfs / rootfs rw 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
sysfs /sys sysfs rw,seclabel,nosuid,nodev,noexec,relatime 0 0
devtmpfs /dev devtmpfs rw,seclabel,nosuid,size=3976812k,nr_inodes=994203,mode=755 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0

The difference with relatime vs.noatime is that it will make changes, but only when the current access time is after the previous access time.

Access time is only updated if the previous access time was earlier than the current modify or change time. (Similar to noatime, but doesn't break mutt or other applications that need to know if a file has been read since the last time it was modified.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.