Tar递归与原始文件夹比较

Kal*_*izi 5 linux bash recursion tar sh

我有一个.tgz文件tar cvzf tartest.tgz tester/*,如果我用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
Run Code Online (Sandbox Code Playgroud)

如果我通过使用比较tar与原始文件夹tar -df tartest.tgz tester/*,一切正常,没有问题,没有错误

如果我在tester文件夹中添加文件20171006_183137.png,然后重试,我会收到错误,如预期的那样:

 tar: tester/20171006_183137.png: Not found in archive
 tar: Exiting with failure status due to previous errors
Run Code Online (Sandbox Code Playgroud)

如果我在tester/tests文件夹中添加文件20171006_183137.png,然后重试,我没有错误和空白输出.

如果我在上次测试中添加-v选项,我只需获取tar中的文件列表.

有没有办法递归比较tar与原始文件夹和子文件夹?

Soc*_*owi 3

该网站称,tar行为符合预期。

\n\n
\n

您应该再次注意,虽然--compare-d ) 确实会导致 tar 报告存档中不存在于文件系统中的文件,但 tar 将忽略活动文件系统中不存在于存档中的文件。

\n
\n\n

您收到的错误tar -df tartest.tgz tester/*确实是一个错误(!),而不是像 \xc2\xbb存档和目录不同\xc2\xab这样的消息。tar不知道如何处理不在存档中的文件。

\n\n

如果您还想以其他方式进行比较,您可以使用此答案中描述的方法(安装或解压存档并diff -r针对原始目录使用)。

\n\n

如果您只对文件的存在而不是内容、访问日期等感兴趣,则可以列出存档和原始目录中的文件名,并将它们与diff

\n\n
diff <(tar -tf tartest.tgz | sort) <(find tester/ | sort)\n
Run Code Online (Sandbox Code Playgroud)\n\n

仅当文件名中不存在换行符时,该命令才有效。
\n使用diff -ycomm命令以获得更具可读性的输出。

\n