Running ubuntu 12.04, I want to compare 2 directories, say folder1/ and folder2/ and copy any files that are different to folder3/. There are also nested files, so matching subdirectories should be copied as well
Is there a single command that would help me? I can get the full list of changed files running:
rsync -rcnC --out-format="%f" folder1/ folder2/
But rsync doesn't seem to have the ability to "export" these files on a different target directory. Can I pipe the list to cp or some other program, so that the files are copied, while the directories are created as well? For example, I tried
rsync -rcnC --out-format="%f" folder1/ folder2/ | xargs cp -t folder3/
but that wouldn't preserve directories as well, it would simply copy all files inside folder3/