如何比较两个tarball的内容 [英] How to compare two tarball's content

查看:99
本文介绍了如何比较两个tarball的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据文件名和文件内容告诉两个tarball文件是否包含相同的文件,不包括日期,用户,组之类的元数据.

I want to tell whether two tarball files contain identical files, in terms of file name and file content, not including meta-data like date, user, group.

但是,有一些限制: 首先,我无法控制制作tar文件时是否包含元数据,实际上,tar文件始终包含元数据,因此直接区分两个tar文件不起作用. 其次,由于一些tar文件太大,以至于我无法将它们解压缩到一个临时目录中并一一比较包含的文件. (我知道是否可以将file1.tar解压缩到file1/中,我可以通过在file/中调用'tar -dvf file2.tar'来进行比较.但是通常我什至不能负担得起其中之一)

However, There are some restrictions: first, I have no control of whether the meta-data is included when making the tar file, actually, the tar file always contains meta-data, so directly diff the two tar files doesn't work. Second, since some tar files are so large that I cannot afford to untar them in to a temp directory and diff the contained files one by one. (I know if I can untar file1.tar into file1/, I can compare them by invoking 'tar -dvf file2.tar' in file/. But usually I cannot afford untar even one of them)

有什么主意我可以比较两个tar文件吗?如果可以在SHELL脚本中完成,那就更好了.另外,有没有办法在不实际解压缩tar的情况下获取每个子文件的校验和?

Any idea how I can compare the two tar files? It would be better if it can be accomplished within SHELL scripts. Alternatively, is there any way to get each sub-file's checksum without actually untar a tarball?

谢谢

推荐答案

tarsum is almost what you need. Take its output, run it through sort to get the ordering identical on each, and then compare the two with diff. That should get you a basic implementation going, and it would be easily enough to pull those steps into the main program by modifying the Python code to do the whole job.

这篇关于如何比较两个tarball的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆