In general, you should copy the timestamps, because this allows rsync
to run more efficiently in future.
But there may be times when you really don't want to keep the timestamps in sync. For example, git
keeps changing the timestamps on your files, but when you run rsync you don't want to see these timestamps being transferred, you only want to see the files which have really changed.
--no-times
will avoid copying the timestamp, but if a file is updated, the target file will have its modification time set to now. That means the timestamps will now differ, so the next rsync
will think an update is needed, and will send it again!
To avoid this, --ignore-times
will not help, because it causes all files to be updated.
What you can do is use --checksum
, which is hard work for rsync, but it will do what you want: it will ignore the timestamps, and only update a file if its actual contents have changed.
So you might like to use a command like this:
rsync -i -a --no-times --checksum /source/Linux/ /destination/Linux
Alternative approach
If you want to keep rsync efficient, then you should keep the timestamps in sync.
But if you don't want to see updates which are only timestamp changes, then you can hide these from the output:
rsync -ai /source/Linux/ /destination/Linux |
grep --line-buffered -v '^.[fd]\.\.t\.\.\.\.\.\. '
Please note that if you take this approach, you will get grep
's exit code, instead of rsync
's! So this may not be suitable for scripting, because the exit code may be misleading. You can work around that using pipefail or PIPESTATUS.
In the end, I used this:
rsync_ai_with_quiet_timestamps() {
# This will not send timestamps, and not check timestamps, but it is slow
#rsync -a --no-times --checksum -i "$@"
# This will send timestamps, but hide updates which are only timestamp changes
(
set +e
rsync -ai "$@" |
grep --line-buffered -v '^.[fd][.][.]t[.][.][.][.][.][.] '
exit "${PIPESTATUS[0]}"
)
}
...
rsync_ai_with_quiet_timestamps /source/Linux/ /destination/Linux
rsync
next time to find out what has changed. The alternative is to use checksums, which are much slower.