0

I'm trying to do almost the same in this question: Rsync : copying over timestamps only

But in this case, some os the files were already modified...

There is any way to change just the timestamp between folder A (original) to B (new one) just by the filename... because filenames is still the same in the 2 places.

i was thinking maybe use touch script, but it seems to be harder, if there is an option using rsync its just one command and Bingo!

Thanks!

2 Answers2

3

rsync doesn't have the ability to do what you are looking for. However, you are in luck because both sets of files are on the same machine, therefore you can use the -r flag of touch to copy the timestamp of one file to another.

You can use find to copy the dates on /source/files and set the timestamps on /files/to/change

This will output the commands that will copy the timestamps, but not actually execute them:

cd /source/files && find . -type f -exec echo touch -r '{}' /files/to/change/'{}' ';'

The output is a list of commands you can execute to copy the timestamps. I would paste 1-2 of them into bash and make sure they do what you expect (use ls -l to check the timestamps of both files before and after). If the commands do what you expect, re-run the find command but remove the echo and the commands will be executed instead of just listed out like before.

TomOnTime
  • 8,381
1

it's an old thread, but I would like to update it. In fact, rsync is able to do that. Hence, I use it with the option --times and --size-only as well as --archive:
--archive: Archive mode; it equals -rlptgoD (no -H, -A, -X). It preserves symbolic links, permissions, timestamps, group, and owner.
--size-only: Skips files that match in size. This prevents unnecessary copying of files that are already identical in content.
--times: Preserves modification times.
-z: compress to speed up things.

Do something like rsync -avz --size-only --times [user@sourceMachine:]/path/to/source/ /path/to/destination/ with success. Extra tip: Use --dry-run to check before execution.