I am using rsync-3.2.3 on Fedora 33 (GNOME).
But how can I keep the access time (atime
) for my files and folders?
I can only keep the modified time (mtime
) with this command:
rsync -t
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI am using rsync-3.2.3 on Fedora 33 (GNOME).
But how can I keep the access time (atime
) for my files and folders?
I can only keep the modified time (mtime
) with this command:
rsync -t
You can ask to preserve atime
(access time) on the source with the --noatime
flag, but on filesystems mounted with relatime
(the modern default) or noatime
this already isn't strictly necessary
rsync -av --noatime src/ dstHost:dst/
I know of no option to preserve atime
on the destination as a copy of the source natively within rsync
. If you have access to the target system you might be able to iterate across the copied tree. Something like this could work on a GNU/Linux type system
( cd src/ && find -type f -print0 ) |
ssh dstHost 'cd dst && while IFS= read -r -d "" f; do touch -a -d "@$(stat -c %Y "$f")" "$f"; done'
Or if you are processing a copy between two local filesystems
( cd src/ && find -type f -print0 ) |
( cd dst && while IFS= read -r -d "" f; do touch -a -d "@$(stat -c %Y "$f")" "$f"; done )
Basically these two snippets do the same thing: for each file in the source, find the corresponding file in the destination and update its atime
to match its mtime
.
ctime
you'll update mtime
. And when you change mtime
you reset ctime
. You cannot control both. I've updated my answer to show a possible method for updating atime
from mtime
. On some versions of stat
you might be able to use this for managing btime
too
– roaima
Jan 21 at 20:47