How to archive files with Tar in the Linux terminal

There are two types of compression: lossless and lossy. Lossy compression achieves a greater reduction in file sizes by carefully discarding data that doesn't greatly affect the results. JPEG and MP3 files use lossy compression.

Archiving uses lossless compression and uncompresses the result to get you back exactly where you started. There are a number of lossless compression methods available, but here are some of the most common.

  • Deflate This is the default compression used by Zip; it is old and not particularly effective, but is fast and well supported.
  • Compress This is an old Unix compression program. Its files have a .Z extension, but you are unlikely to see many in the wild. There are also patent issues with it.
  • Gzip This Compress replacement is completely open and still in use today. Gzip uses Deflate, but generally produces smaller archives than Zip with its default settings. It does not give the best compression, but it compresses and decompresses quickly, making it a good choice when size is not the most vital consideration.
  • Bzip2 This is a more efficient compressor, but at the expense of speed. Compression in particular can be slower, but it produces more compact results.
  • xz This more recent program uses the LZMA2 compression algorithm also used by 7-Zip. It is fast – particularly for decompression – and works brilliantly. It is the compressor of choice for many key Linux projects, including Coreutils and the kernel itself.

Compression types

Here is the same archive using different compression programs. The Gzip version is significantly larger, but it's faster to compress and decompress.