How to print files that would have been changed using rsync?
Is there a way to get rsync to print the full filepaths to all files that are different without actually transferring any files?
Alternatively, I need a way to diff the files across two trees (over SSH) based only on change in size or last-modified time.
Rsync has a dry-run
option:
-n, --dry-run show what would have been transferred
I am not sure if this is what you want.
If you want to diff
the files across two trees, you could maybe recursively search the two directions with find and pipe to output to ls and pipe both to a file. You could then use diff
to compare the files.
I prefer to use the --out-format to see the details, piping it to less:
rsync -azh --dry-run --delete-after --out-format="[%t]:%o:%f:Last Modified %M" source destination | less
rsync -rvn localdir targetdir
The -n means to show actions only (without any action being performed).
Note that you need the 'v' or it won't show you anything! (the rest of the answers forget this...)
Building on other answers and https://serverfault.com/a/618740/114520
- use
--dry-run
(or-n
) to avoid modification - use
--itemize-changes
(or-i
) to find changes - use
--archive
(or-a
) to get all subdirectories - use
egrep
to filter out entries starting by dot (no change)
Which gives you: rsync -nia source destination | egrep -v "sending incremental file list" | egrep -v "^\."
If you just want one way, you may change the command:
- for changes from source to destination:
rsync -nia source destination | egrep -v "sending incremental file list" | egrep -v "^(\.|<)"
- for changes from destination to source:
rsync -nia source destination | egrep -v "sending incremental file list" | egrep -v "^(\.|>)"
And if you need only the files, just add awk
magic: rsync -nia source destination | egrep -v "sending incremental file list" | egrep -v "^\." | awk '{print $2}'
The truth of the matter is that if you run rsync -v ...
and it outputs a filename to the screen, that file is being transferred (or would have been transferred, if you are doing a --dry-run). To ascertain why rsync was about to transfer it, use itemize mode: https://serverfault.com/a/618740/27813
As others have noted, by default rsync just compares based on file size and timestamp, which both have to match else a "delta copy" is started on that file. If you really want to see which files are different, use "-c" checksum mode.