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.

2 Answers 2


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.


In addition to the @Lekensteyn answer, I'd like to add that this behavior is based on Do one thing and do it well philosophy - tar program knows how to put multiple files into a single stream (with .tar extension), gzip knows how to compress a single file (adding .gz extension)*. By combining those tools you can create a command which compresses multiple files into a single .tag.gz file.

This approach is very flexible - you can combine a few standard Unix commands to do all sorts of things. For example, if you write a better program to compress files you don't need to modify tar to enable it to create .tar.mymegazip files - instead, you just pipe tar's output to your compressor.

Similarly, tar knows nothing about SSH, but by combining commands you can create a script which archives files, uploads them to a remote machine via SSH and un-archives them there.

Compare this to zip command, which did not originate in Unix - it has built-in tools to compress whole directories, encrypt files, split the archive into smaller zipfiles etc.

(footnote) - yes, tar is able to gzip or bzip files itself using -z and -j switches, they were added for convenience, and GNU tar is actually spawning gzip or bzip2 as a new process.

  • Example: the commands tar c dir/ | gzip > dir.tar.gz and tar czf dir.tar.gz dir/ commands do the same thing. An example where tar is combined with SSH and tar (again): tar cz Documents/ | ssh user@host 'tar xz (rsync equivalent would be: rsync -a Documents user@host:)
    – Lekensteyn
    Dec 5, 2013 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .