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.
Leave a Reply