Score:0

How to preserve file access time when using `chmod`

cn flag

I would like to know how can I preserve file access time ("atime") when using "chmod". Sometimes I need to use the code below:

chmod -R 777 /directory

It works fine, however all the files inside that directory have the access time ("atime") changed to the current time. Do you have any idea?

NOTE: I am using CentOS 8.

Tom Yan avatar
in flag
I can (only) think of "stupid" method like using `find`, `stat` and `touch` accordingly to "revert" the access time after `chmod`ing each file. (It's probably more complicated, if feasible at all, if you also want to retain the access time of the (sub)directories.)
Jonathan avatar
cn flag
What amazes me is that even files that are already with permission 777 have their timestamp updated when chmod is executed on them also with 777. chmod should not touch those files if their permission is the same the one being assigned.
Tom Yan avatar
in flag
Ugh, it's not really supposed to "change" the permission. It's like `echo -n meh > some_file` will still nuke `some_file` and write `meh` to it even if its content is already just `meh`.
Tom Yan avatar
in flag
Btw, you might also want to consider/try `mount -o remount,noatime` the corresponding mountpoint.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.