Hi I am looking for a command on macOS 11.6 to copy the access time from source file to destination file.
The access time source file must not be updated.
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.Sign up to join this community
touch -a -r sourcefile destinationfile
This only changes access time, while my other example changed both access and modification time on the destination. See
man touch for details.
Note: On macOS 11.6, 10.14 (and probably earlier), if the touched file is non-zero length and in a folder indexed by Spotlight, Spotlight will update the access time to the current time soon after the access time is set. Preferences/Spotlight/Privacy can be used to exclude folders from Spotlight indexing.
cp -p source destination
will do the job.
From man pages :
-p Cause cp to preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, user ID, and group ID, as allowed by permissions. Access Control Lists (ACLs) and Extended Attributes (EAs), including resource forks, will also be preserved.