YuuY
YuuY

Reputation: 107

When does the atime of a directory in linux change?

The atime of a directory doesn't change when I access it using the ls command.
So what does the atime of a directory in Linux mean? And when does it change?

Upvotes: 3

Views: 2585

Answers (1)

Alex D
Alex D

Reputation: 30455

The atime of a directory is the last time the directory was "read" to see what files are in it. And when does it change? Just what you thought: when you do things like run ls.

So why didn't the atime change when you tried running ls in a directory?

As the comments mention, if the filesystem was mounted with noatime or nodiratime flags, then the atime will not be updated. This is a performance optimization. But you also commented that your filesystem was not mounted with noatime or nodiratime.

I'm guessing your mount flags might have included relatime. That's a common one. It is also added for performance, but rather than completely avoiding updates to atime, it reduces how frequently those updates are made.

When your filesystem is mounted with relatime, and you read a file or directory, the atime is only updated if

  1. the atime is older than the ctime (change time) or mtime (modification time), or
  2. if the atime is more than a day in the past.

That is probably why the atime was not updated in the case you mentioned.

Upvotes: 4

Related Questions