Skip to content

How to copy just timestamps, or "I should have used cp -p"

An answer to this question on the Unix & Linux Stack Exchange.

Question

I foolishly copied a very large amount of data using cp -r.

Looking at it now, I've realized that this means I lost my file modification times. I should have used cp -rp.

My directory structure and files haven't changed: is there any way to copy over just the attributes/timestamps now? I'm thinking rsync might be useful.

Answer

This worked well for me:

rsync -vrt --size-only /src /dest

/src being folder which timestamps are correct and wanted. /dest folder files will acquire modification times of the /src folder files. Create times remained unchanged.

The --size-only command compares files only based on size, which was largely unchanged for me. The -t copies over the timestamps.