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