1

I just transferred 1.8TB of data from an external hard drive to an internal hard drive using rsync, but I didn't add the "-t" flag, so the "Date Modified" for every file on the internal hard drive is now the date I ran rsync.

Is there a way to copy the dates from the source files to the destination files without having to delete the destination files and run rsync again with the "-t" flag?

0

Touching 'modified' to a file from another reference file can not be done with rsync.

However we can user the touch command to do so.

touch -m -r source/path/file dest/path/file

Above will touch the 'modified' date from the source to the destination file path.

This can further be scripted, e.g. below for all files in a given destination directory provided filenames are identical:

 for i in *; do touch $i -m -r /path/to/source/$i; done
  • Thanks Takkat! I'm looking for something that will be recursive through multiple directories. Somebody on another forum posted the following: 'find /home/abcdefg/ -exec touch {} \; The abcdefg directory itself will be included. ' – user217685 Nov 21 '13 at 6:03
  • Never used find before though. Not entirely sure what the brackets or the final slash do either. – user217685 Nov 21 '13 at 6:17
  • @user217685: yeah find is better for recursiveness. The {} is a placeholder for the filename found, however after doing a quick test yesterday I did not get desired results on different paths so I posted the loop approach. – Takkat Nov 21 '13 at 7:14
0

Recursive with find and touch

cd /source/dates/dir
find . -exec touch -c -m -r {} /destination/dates/dir/{} \;

Changing directory is important in order to get a relative path with find.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.