I've copied a large directory to another location (through a network). I needed to preserve all the timestamps (especially ctime and mtime). However somewhere in the process I screwed things up. (I probably made a typo in the flags.) And all the files have new timestamps now. I still got the directory with the correct timestamps. But I don't want to copy it all again because it took me days. Can I somehow just sync the filestamps, e.g. with rsync? Note that this has to be done through a ssh tunnel over a network that is rather slow. The PCs on both ends however are quite fast.


Yes, rsync is your best bet. Something like this should work:

rsync -vr --size-only --times <source> <dest>

--size-only tells rsync not to copy the files again, --times tells it to update timestamps.

| improve this answer | |
  • The "--size-only" will work but I don't think it's necessary. The regular rsync algorithm (comparing checksums) will work just fine. – RJHunter Jul 4 '16 at 8:53
  • @RJHunter Did you actually try it? It will re-transfer the files, because the timestamps differ. – Satō Katsura Jul 4 '16 at 9:00
  • If rsync does "re-transfer" a file, it's usually very fast and uses little data. The rsync protocol is specifically designed to transmit only a small amount of data when both sides have similar or identical files. This is the "speedup" that rsync prints on completion. (Note that the rsync tool doesn't bother with delta-transfer when syncing local-to-local, because this is only a benefit over a network.) – RJHunter Jul 4 '16 at 14:16
  • @RJHunter From the OP: I've copied a large directory to another location (through a network). – Satō Katsura Jul 4 '16 at 14:18
  • Indeed, the OP will benefit from the speed-up of delta-transfer because of the network, as long as rsync is being used in its normal network mode. Copying from a mounted network share to a local disk would be "local-to-local" as far as rsync is concerned, so it would not benefit from the rsync protocol's delta-transfer speedup. – RJHunter Jul 4 '16 at 14:27

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.