linux – tar与原始文件夹递归比较
我有一个用tar cvzf tartest.tgz tester / *制作的.tgz文件,如果我用tar –list -f tartest.tgz文件列出tar,我有以下结构
tester/2017-08-02_131404.png tester/cfg.pdf tester/tests/ tester/tests/1.png tester/tests/2.png tester/tests/3.png tester/tests/4.png tester/tests/5.png 如果我使用tar -df tartest.tgz tester / *将tar与原始文件夹进行比较,一切正常,没有问题,没有错误 如果我在tester文件夹中添加文件20171006_183137.png,然后重试,我会收到错误,如预期的那样: tar: tester/20171006_183137.png: Not found in archive tar: Exiting with failure status due to previous errors 如果我在tester / tests文件夹中添加文件20171006_183137.png,我没有错误和空白输出. 如果我在上次测试中添加-v选项,我只需获取tar中的文件列表. 有没有办法递归比较tar与原始文件夹和子文件夹? 解决方法
根据
this site,tar的行为符合预期.
你得到的tar -df tartest.tgz tester / *的错误确实是一个错误(!),而不是像“存档和目录不同”这样的消息. tar不知道如何处理存档中没有的文件. 如果您还想比较其他方法,可以使用this answer中描述的方法(安装或解压缩存档并对原始目录使用diff -r). 如果您只对文件的存在感兴趣而不是内容,访问日期等,则可以从存档和原始目录中列出文件名,并将它们与diff进行比较: diff <(tar -tf tartest.tgz | sort) <(find tester/ | sort) 仅当没有包含换行符的文件名时,该命令才有效.使用diff -y或comm命令获得更易读的输出. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |