Copy *changed/new files only* to a DIFFERENT directory?
If you only need to see which files will be affected, without seeing the differences between them, you can use the --dry-run
option to rsync. Let's set up a sandpit for testing:
$ cd /tmp
$ mkdir -p testing/{a,b}
$ cd testing/
$ touch a/hello a/world
$ ls a
hello
world
$ rsync -rv --append-verify a/ b
$ ls b
hello
world
Now perform modifications to the contents of a
:
$ echo 123 > a/hello
$ touch a/abc
Now use rsync ... --dry-run ...
to see what would happen:
$ rsync -rv --append-verify --dry-run a/ b
sending incremental file list
abc
hello
sent 103 bytes received 22 bytes 250.00 bytes/sec
total size is 4 speedup is 0.03 (DRY RUN)
We can see no changes were actually made to b
:
$ ls b
hello
world
$ cat b/hello
$
If you need to see the differences between the directories you can use diff
:
$ /bin/diff -aurN a b
diff -aurN a/hello b/hello
--- a/hello 2018-12-13 08:16:23.376761456 +1100
+++ b/hello 2018-12-13 08:16:11.306761686 +1100
@@ -1 +0,0 @@
-123
If b
is on a remote box and you need to see the differences, you'll need to create a local copy of b
and then you can diff
.
I believe a better answer is in https://serverfault.com/a/508272/173599. Here I quote the relevant command:
rsync -aHxv --compare-dest=folder2/ folder1/ folder3/
To compare folder1
with folder2
as destination, but copy instead in folder3
.