Why is sorting files by access time not working

atimefilesfilesystemsls

I tried to use command
ls --time=atime

it was working in one directory but wasn't working in another directory.
I opened certain files in vim, evince and other applications but after the
command file access times weren't changed.

When I type touch file.txt the access time is changed, but when I type vim file.txt the access time is not changed.

What is wrong here?

Best Answer

With default mounts options, access times are handled in a special way on linux:

relatime – A filesystem mount with this option causes the access time to be updated if they are (before the update has occurred) earlier than the modification time. This significantly cuts down the writes caused by atime updates.

The relatime mount option was made the default option since linux kernel 2.6.30. That is the reason for ls --time=atime not listing what you expect.

Solution: To use strict (legacy) behavior for atime use the strictatime mount option (e.g. in /etc/fstab).

Note: To completely disable atime updates, one can use noatime.