How to determine a tar archive's format

倖福魔咒の 提交于 2019-12-12 09:59:37

问题


In Linux, how can I determine the format which was used to create a given tarball?

I'd like to detect whether a given archive was created using posix or gnu format.

I've already read the man page for GNU tar, which explains how to control the format during creation. However, I don't see anything about how to view the format of an existing file.


回答1:


You can use file under Linux to look at the fingerprint of the uncompressed archive (file won't peer beyond the compression layer, so decompress it first):

$ tar --format=posix -cf posix.tar foo      # create test posix archive
$ tar --format=gnu   -cf gnu.tar   foo      # create test gnu archive
$ file gnu.tar posix.tar
gnu.tar:   POSIX tar archive (GNU)
posix.tar: POSIX tar archive

If the archive is compressed, decompress it first:

$ tar --format=posix -czf posix.tar.gz foo  # create test gzip posix archive
$ tar --format=gnu   -czf gnu.tar.gz   foo  # create test gzip gnu archive
$ gunzip posix.tar.gz
$ gunzip gnu.tar.gz
$ file gnu.tar posix.tar
gnu.tar:   POSIX tar archive (GNU)
posix.tar: POSIX tar archive

GNU is based on an older POSIX format, so that is why it says it is both.

For the nitty gritty details, the format is described in the GNU tar manual here and more details here.



来源:https://stackoverflow.com/questions/37603510/how-to-determine-a-tar-archives-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!