2

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?

  • What does stat file show for the access time? Same thing? – Mark Plotnick Jan 17 '16 at 14:22
  • @MarkPlotnick: Yes, it gives the same access time as ls -lu. – wolf-revo-cats Jan 17 '16 at 15:20
4

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.).

  • It does not even work if I use the mount option strictatime. – wolf-revo-cats 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 9:15

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.