Why is cat not changing the access time?
http://en.wikipedia.org/wiki/Stat_(system_call)
Writing to a file changes its mtime and ctime, while reading a file changes its atime. As a result, on a POSIX-compliant system, reading a file causes a write, which has been criticized. This behaviour can usually be disabled by adding a mount option in /etc/fstab.
However, turning off atime updating breaks POSIX compliance, and some applications, notably the mutt mail reader (in some configurations), and some file usage watching utilities, notably tmpwatch. In the worst case, not updating atime can cause some backup programs to fail to back up a file.
Linux kernel developer Ingo Molnár called atime "perhaps the most stupid Unix design idea of all times," adding: "[T]hink about this a bit: 'For every file that is read from the disk, lets do a ... write to the disk! And, for every file that is already cached and which we read from the cache ... do a write to the disk!'" He further emphasized the performance impact thus:
Atime updates are by far the biggest IO performance deficiency that Linux has today. Getting rid of atime updates would give us more everyday Linux performance than all the pagecache speedups of the past 10 years, combined.
how to know if noatime or relatime is default mount option in kernel?
man mount
....
relatime
Update inode access times relative to modify or change time.
Access time is only updated if the previous access time was ear‐
lier than the current modify or change time. (Similar to noat‐
ime, but doesn't break mutt or other applications that need to
know if a file has been read since the last time it was modi‐
fied.)
Since Linux 2.6.30, the kernel defaults to the behavior provided
by this option (unless noatime was specified), and the stricta‐
time 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.
....
Which is how that particular partition was mounted and why cat does not update the access time as I expected.
Related videos on Youtube
nelaaro
Linux admin, tech enthusiast. opensource evangelist.
Updated on September 18, 2022Comments
-
nelaaro over 1 year
The second call to cat a file does not update the access time. I was expecting the access time to be updated ever time a file contents gets displayed.
I see the same behaviour if I open the file in web browser. Its access time does not get updated consistently.
Am I misunderstanding access time? What is different between the two cat calls?
$ touch test $ stat test File: `test' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 803h/2051d Inode: 152694 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1001/ aaron) Gid: ( 1001/ aaron) Access: 2012-08-21 11:05:40.586020996 +0200 Modify: 2012-08-21 11:05:40.586020996 +0200 Change: 2012-08-21 11:05:40.586020996 +0200 Birth: - $ vim test $ stat test File: `test' Size: 5 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 152694 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1001/ aaron) Gid: ( 1001/ aaron) Access: 2012-08-21 11:05:52.890021630 +0200 Modify: 2012-08-21 11:06:31.606023626 +0200 Change: 2012-08-21 11:06:31.638023629 +0200 Birth: - $ cat test test $ stat test File: `test' Size: 5 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 152694 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1001/ aaron) Gid: ( 1001/ aaron) Access: 2012-08-21 11:06:44.662024298 +0200 Modify: 2012-08-21 11:06:31.606023626 +0200 Change: 2012-08-21 11:06:31.638023629 +0200 Birth: - $ cat test test $ stat test File: `test' Size: 5 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 152694 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1001/ aaron) Gid: ( 1001/ aaron) Access: 2012-08-21 11:06:44.662024298 +0200 Modify: 2012-08-21 11:06:31.606023626 +0200 Change: 2012-08-21 11:06:31.638023629 +0200 Birth: -
-
nelaaro over 11 yearsMore info about how ubuntu handles atime askubuntu.com/questions/2099/…
-
nelaaro over 11 yearsHere is an older discussion on how atime is affected by different mount options. linux.koolsolutions.com/2009/01/30/…