How to Preserve File Timestamps with Rsync on Linux

Quick Linux Tip #82:

Question: After copying files, timestamps changed. How do I preserve them?

Try: rsync -a --preserve-times /source/ /destination/

Info: rsync -a (archive mode) preserves modification timestamps (-t), permissions, ownership, and symbolic links. Adding --preserve-times explicitly ensures file modification times remain unchanged during the transfer.

Examples:

  • $ cp --preserve=timestamps file1 file2  # Preserve timestamps with standard copy
  • $ touch -r reference_file target_file  # Copy timestamps from a reference file
  • $ find . -exec touch -r /reference {} +  # Sync directory timestamps in bulk

Note: -a is shorthand for -rlptgoD, so it already includes timestamp preservation through -t. Preserving modification timestamps is useful for build tools like make, incremental backups, and forensic auditing.




LinuxTeck.com
linuxteck:~$ rsync -a --preserve-times /source/ /destination/

linuxteck:~$ stat -c '%y %n' /source/report.pdf
2026-01-15 09:23:45.123456789 +0000 /source/report.pdf

linuxteck:~$ stat -c '%y %n' /destination/report.pdf
2026-01-15 09:23:45.123456789 +0000 /destination/report.pdf

linuxteck:~$ ls -la /destination/report.pdf
-rw-r--r-- 1 linuxteck linuxteck 456789 Jan 15 09:23 /destination/report.pdf
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #81: How to Find Which Process Uses Too Many Open Files in Linux NEXT ARTICLE Quick Linux Tip #83: How to Create an Encrypted Compressed Backup in Linux
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.