Ubuntu – the difference with all the different types of .tar archives

filemanagertar

Could anyone tell me what is up with so many archives, and how are they differ?

There's at least five that I can think of, .tar.tz, .tar.gz, .tar.bz2, .tar.lz, .tar.z

Which is best for what applications? It just seems silly to make so many variations of the same file but I'm sure there's a reason.

Best Answer

The .gz, .xz, .bz2, .7z, .lz, .z suffixes are used to make clear that the file is compressed with said compression algorithm. Its use is not limited to .tar files, you will also see files such as initrd.gz (an compressed initial ramdisk) or manual.txt.gz (for a compressed text document). You may also see file.tgz which is also indicates a gzip-compressed tarball (like file.tar.gz).

The file extension is a convention, it does not necessarily describe the file contents. To check what kind of file you are handling, use the file command. Example:

$ file data.tar.gz
data.tar.gz: gzip compressed data, from Unix
$ gunzip -c data.tar.gz | file -
/dev/stdin: POSIX tar archive (GNU)

In my experience, gzip-compressed files (.gz) are the most common ones. It is fast in compressing and decompressing, though there are other algorithms that yield better compression ratios.