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.

  • Yes, rsync would be useful. In general, you only have to run rsync with the same source and dest as the original cp -r. but test it with rsync --dry-run first.
    – cas
    May 24, 2016 at 4:05

2 Answers 2


This worked well for me:

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

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


You can do this with find and touch.

cd destination
find -depth -exec touch -r /path/to/source/{} {} \;

The -depth option arranges for directories' times to be set after their contents have been set. This assumes that your find interpolates {} when it's a substring of an argument. If it doesn't, invoke a shell:

find -depth -exec sh -c 'for x; do touch -r "$0/$x" "$x"' /path/to/source {} +

To copy the access times as well, run touch -a … as well.

find -depth -exec touch -a -r /path/to/source/{} {} \; -exec touch -r /path/to/source/{} {} \;

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.