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.
A tar (tape archive) file format is an archive created by tar, a UNIX-based utility used to package files together for backup or distribution purposes. It contains multiple files (also known as a tarball) stored in an uncompressed format along with metadata about the archive. Tar files are not compressed archive files.
WinZip opens and extracts TAR Compressed Archive Files—and many more formats.
In computing, tar is a computer software utility for collecting many files into one archive file, often referred to as a tarball, for distribution or backup purposes. The name is derived from "tape archive", as it was originally developed to write data to sequential I/O devices with no file system of their own.
You can use file
under Linux to look at the fingerprint of the uncompressed archive:
$ touch foo # create test file
$ tar --format=posix -cf posix.tar foo # create test posix archive
$ tar --format=gnu -cf gnu.tar foo # create test gnu archive
$ file posix.tar gnu.tar
posix.tar: POSIX tar archive
gnu.tar: POSIX tar archive (GNU)
If the archive is compressed, decompress it first, because file
won't peer beyond the compression layer:
$ touch foo # create test file
$ 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
$ file posix.tar.gz gnu.tar.gz # show output when compressed
posix.tar.gz: gzip compressed data
gnu.tar.gz: gzip compressed data
$ gunzip posix.tar.gz # decompress to posix.tar
$ gunzip gnu.tar.gz # decompress to gnu.tar
$ file posix.tar gnu.tar # show output after decompression
posix.tar: POSIX tar archive
gnu.tar: POSIX tar archive (GNU)
Or, check the compressed archives without saving the decompressed file by piping the output directly to file
's standard input:
$ gunzip --stdout posix.tar.gz | file -
/dev/stdin: POSIX tar archive
$ gunzip --stdout gnu.tar.gz | file -
/dev/stdin: POSIX tar archive (GNU)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With