3

The manpage of ls says:

   -u     with -lt: sort by, and show, access time; with -l: show access time and sort by name;
          otherwise: sort by access time

but that doesn't seem to work:

test@debian:~$ date > file
test@debian:~$ date
Sun Jan 17 13:21:12 CET 2016
test@debian:~$ cat file 
Sun Jan 17 13:20:10 CET 2016
test@debian:~$ ls -lu file 
-rw-r--r-- 1 test test 29 Jan 17 13:21 file
test@debian:~$ date
Sun Jan 17 13:22:02 CET 2016
test@debian:~$ cat file 
Sun Jan 17 13:20:10 CET 2016
test@debian:~$ ls -lu file 
-rw-r--r-- 1 test test 29 Jan 17 13:21 file

One should expect instead (since the last access time was at 13:22 or later) something like:

-rw-r--r-- 1 test test 29 Jan 17 13:22 file

What is the explanation? Is the file buffered?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
viuser
  • 2,564
  • 3
  • 29
  • 57

1 Answers1

6

Your filesystem is mounted with relatime by default. Access times will not be updated, if they're already newer than or equal to the modified time of the file.

This is an (POSIX-violating) optimization, to avoid every single file read causing a write to the disk.

Apparent atime updates are not affected by buffering. (lazyatime will buffer atime for up to 24 hours - but the in-memory atime will be updated every time, and that's what ls will show.).

sourcejedi
  • 48,311
  • 17
  • 143
  • 296
  • It does not even work if I use the mount option `strictatime`. – viuser Jan 17 '16 at 15:33
  • `mount -oremount,strictatime /` makes it (temporarily) work for me. I don't have /home on a separate partition. You need to show us your mount details e.g. `grep -w /home /proc/mounts`. Replace /home with / if necessary. – sourcejedi Jan 17 '16 at 20:32
  • "Access times will not be updated, if they're already older or equal to" — should that be "newer or equal to"? – Celada Jan 17 '16 at 23:28
  • @Celada ah-heh, fixed. – sourcejedi Jan 18 '16 at 09:15