Unsure why access time on a directory change isn't changing

Hello... And thanks in advance for any help anyone can offer me

I was trying to work out the differences between displaying modify, access, and change times with the 'ls' command. Everything seems in order when I look at files, but the access time on a directory doesn't seem to change when I expect it too.

I'm sure I must have the concept misunderstood with a directory... But when I 'cd' to a directory like 'Downloads' or do an 'ls' to view it's contents... And then look at it's last access time with 'ls -ldu' or 'stat'... It does not change

It has changed when I wasn't paying attention and has a date/time from yesterday... I just don't understand what would caused it to change

Can someone straighten me out here? THANKS!

I think access time includes reads too, if its enabled. But its been so long since I've seen a system that had atimes enabled, I'm not 100% positive.

Unless you know for a fact atimes are enabled on your filesystem, they may not be meaningful. atimes are a lot of disk writes for something so rarely used, and often turned off. I usually see them disabled in Linux by default. (It's an option when mounting the filesystem - 'noatime'.)

2 Likes

You didn't say which operating system this is but there has to be difference between read and open. If you think about it, if a read updated the access time then all the access times would change when a backup is run which wouldn't be any good if you had to restore the whole lot. However, if an application opens a file then that will update the access time. For example, if you open a file with vi and then immediately quit with :q! , the access time should update because the file has been specifically opened. Additionally, if you vi followed by :w! (even if you haven't changed anything) the file will be written back so the modified date should change.

Now with a directory it is holding the details of its files so if a new file is created the directory is modified. Also, if an application specifically opens a file with that directory in its pathname (and blocks may need to be allocated/deallocated to the file), then the access time should change.

You should be able to verify this on your operating system with a few tests.

2 Likes

Yes, the OS matters. Recent Linux distros do not alter atime as often as Unix does (and older Linux did).
Also the file system type matters.

cat /etc/*release || uname -sr
df .
1 Like

Thanks to all that replied! Yes the OS mattered... I was on CentOS 7 and the filesystem was mounted with an option known as "relatime". Which only seems to record atime in 3 different instances. Got it figured out!

2 Likes