加入收藏 | 设为首页 | 会员中心 | 我要投稿 常州站长网 (https://www.0519zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

linux – 比较2个目录并复制第3个目录中的差异

发布时间:2020-12-24 23:43:29 所属栏目:Linux 来源:网络整理
导读:运行ubuntu 12.04,我想比较2个目录,比如folder1 /和folder2 /,并复制任何与folder3 /不同的文件.还有嵌套文件,因此也应复制匹配的子目录 有一个命令可以帮助我吗?我可以获得运行的已更改文件的完整列表: rsync -rcnC --out-format="%f" folder1/ folder2

运行ubuntu 12.04,我想比较2个目录,比如folder1 /和folder2 /,并复制任何与folder3 /不同的文件.还有嵌套文件,因此也应复制匹配的子目录

有一个命令可以帮助我吗?我可以获得运行的已更改文件的完整列表:

rsync -rcnC --out-format="%f" folder1/ folder2/

但是rsync似乎没有能力在不同的目标目录上“导出”这些文件.我可以将列表传递给cp或其他程序,以便复制文件,同时创建目录吗?例如,我试过了

rsync -rcnC --out-format="%f" folder1/ folder2/ | xargs cp -t folder3/

但是这也不会保留目录,它只会复制folder3 /中的所有文件

解决方法

使用–compare-dest.

从手册页:

–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.

首先使用–dry-run检查语法

rsync -aHxv --progress --dry-run --compare-dest=folder2/ folder1/ folder3/

一旦你对输出感到满意:

rsync -aHxv --progress  --compare-dest=folder2/ folder1/ folder3/

这个link有一个很好的解释–compare-dest范围.

(编辑:常州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读