1

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
3
  • Are you talking about preserving atime for the source files (i.e. pretending you haven't read them) or for the destination?
    – roaima
    Jan 21 at 14:14
  • For the source and destination. I want to transfer my files and folders (internal disks) to my external USB drive (SD cards, 1 TB hard drive etc.) as a clone (copy). Jan 21 at 14:51
  • Unfortunately I only managed to keep for modified time (mtime), but for access time (atime) I didn't find any rsync command. Is it possible that rsync does not support this and I have to create a report on github because of feature request? github.com/WayneD/rsync/issues Jan 21 at 14:51
1

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.

7
  • I understand and do you also know about change time (ctime)? Is there also here a rsync command for keep? Jan 21 at 17:25
  • 1
    @Laradu9sna7al There's no POSIX-like interface to set ctime. You'd either have to use an interface outside the filesystem, or you'd have to fake it by resetting the system time. Neither are appropriate for a tool like rsync. See also unix.stackexchange.com/questions/36021/…
    – BowlOfRed
    Jan 21 at 18:11
  • @BowlOfRed Very interesting then I find change time (ctime) useless for me. It shows by default in GNU/Linux but I can't keep it when copying Is there a terminal command to disable it? Jan 21 at 19:18
  • @Laradu9sna7al if you change 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
  • @Laradu9sna7al, I'm not sure what disabling it would mean. The space for it is allocated already. It's never written unless something else is written, so it doesn't take any additional I/O. There's no resources that could be returned other than a microscopic amount of CPU. It can be copied if the filesystem is copied (such as via dump), but can't be set on a mounted filesystem (which is what rsync uses).
    – BowlOfRed
    Jan 21 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.