How can I keep file attributes like creation and modified times when copying?
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
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
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
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
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