运行ubuntu 12.04,我想比较2个目录,比如folder1 /和folder2 /,并复制任何与folder3 /不同的文件.还有嵌套文件,因此也应复制匹配的子目录
有一个命令可以帮助我吗?我可以获得运行的已更改文件的完整列表:@H_403_3@
rsync -rcnC --out-format="%f" folder1/ folder2/
但是rsync似乎没有能力在不同的目标目录上“导出”这些文件.我可以将列表传递给cp或其他程序,以便复制文件,同时创建目录吗?例如,我试过了@H_403_3@
rsync -rcnC --out-format="%f" folder1/ folder2/ | xargs cp -t folder3/
解决方法
使用–compare-dest.
从手册页:@H_403_3@
–compare-dest=DIR –
This option instructs rsync to use DIR on the destination machine as an additional hierarchy to compare destination files against doing transfers (if the files are missing in the destination directory). If a file is found in DIR that is identical to the sender’s file,the file will NOT be transferred to the destination directory. This is useful for creating a sparse backup of just files that have changed from an earlier backup. @H_403_3@
首先使用–dry-run检查语法@H_403_3@
rsync -aHxv --progress --dry-run --compare-dest=folder2/ folder1/ folder3/
rsync -aHxv --progress --compare-dest=folder2/ folder1/ folder3/