How can I keep file attributes like creation and modified times when copying?

April 17, 2025 4 answers
Asked by 8mm film splice
I'm looking for a way to copy files while ensuring that all their attributes, especially the creation and modified timestamps, are preserved. For instance, if I have a file on an ExFAT drive with a creation time of 12:34:56.78, I want the copied file on the destination drive to maintain that exact timestamp down to the millisecond. Any tips on how to achieve this?

Answers

red-eye-flight
If you're focused solely on the timestamps, maybe you should consider moving instead of copying. That way, you won't have to worry about it.
Reply to this answer
!rearrange the seats
You can use the `rsync` command for this purpose. It does a great job of preserving most attributes of files, including timestamps.
Reply to this answer
almost an answer
Keep in mind that preserving creation time can be tricky, especially with filesystems like ext4 or btrfs. There are hacks available, like using `debugfs`, but they can be complicated. Also, Iโ€™ve found that copying between ExFAT drives sometimes doesnโ€™t keep the creation time either. Offers no easy solutions depending on the file systems involved.
Reply to this answer
exon_4b
Try the `cp -a source-file destination-file` command. It should help you maintain the attributes during the copy process, but make sure to check the specific behaviors on different file systems.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions