Before copying, rsync decides which files differ. Whether it notices a swapped file depends on how it compares.
rsync brings the destination in line with the source: the source comes first in the command, the destination second. The -a option copies whole directories and carries over modes and modification times, plus the owner when it has the privileges.
Before copying, rsync compares every pair of files. By default this is the quick check: size and modification time. If both match, the file counts as the same, and rsync does not even read its contents. That is why repeating a sync of a large tree is fast.
The two settings.conf files hold mode=stable and mode=broken, lines of the same length, and their modification times were set to the same value. To the quick check they are the same file. This happens when a file's time is set by hand with touch -d or carried over from an archive: tar gives files back the time recorded in the archive.
The -c option compares checksums of the contents: rsync reads every file in full on both sides. It will find the difference, but on a large tree that takes a while. So you reach for -c when there is a reason to distrust size and time.
In ls -l, app.conf in the source and in the copy has the same size and time, but cat prints different lines. What will rsync -a src/ copy/ do?
-
Without
-crsync compares size and time, and they match: it skips the file.rsync -ac src/ copy/replaces it. -
Without
-crsync does not notice different contents: the command finishes silently, as at the start of the lesson. -
rsync asks no questions: it decides what to copy itself, by size and modification time.
Without -c rsync compares only size and modification time, and they match. rsync -ac src/ copy/ compares the contents and replaces the file.
Key points
-
Without
-crsync compares only size and modification time: if they match, the file is not copied. -
-ccompares contents by checksum and reads every file, so it is slower on large trees.