Problem with access time of a file

Joe Hesse

New Member
Joined
Apr 30, 2023
Messages
1
Reaction score
0
Credits
17
My understanding of the access time of a file is that if a file is read and no changes are made, the access time will be the time of reading. The access time of a file is obtained by "$ ls -lu file". The following screen capture, with my comments, shows that I don't understand this correct or made some error. The first time I access the file I got the correct access time, but not the second time.

$ ls -l Test.txt
-rw-r--r--. 1 joe joe 12 Apr 30 09:59 Test.txt <== Test.txt shows last modified time
$ date
Sun Apr 30 10:05:23 AM CDT 2023
$ cat Test.txt <== Access file, don't change contents
Hello World
$ ls -lu Test.txt
-rw-r--r--. 1 joe joe 12 Apr 30 10:05 Test.txt <== Time of access shown as 10:05
$ date
Sun Apr 30 10:06:14 AM CDT 2023 <== Waited a minute
$ cat Test.txt <== Access file, don't change contents
Hello World
$ ls -lu Test.txt
-rw-r--r--. 1 joe joe 12 Apr 30 10:05 Test.txt <== INCORRECT, SHOULD BE 10:06
 


An explanation for the "INCORRECT" output could be that you didn't quite wait the full minute to check the "ls -lu" output. In any case, the stat command will provide definitive information. Try:
Code:
stat Test.txt
 
Ha! I went to write an article about stat the other day and it wouldn't work as expected. I just now remembered that I had it aliased to vnstat.

Entirely off-topic, but even I do something remarkably stupid once in a while.
 

Members online


Top