October 15, 2018

4 Archiving Tools for Linux Server Admins - page 2

tar and zip

  • October 11, 2010
  • By Juliet Kemp

gzip does file compression/decompression, but not archiving. However, it works well when used together with an archiving tool - in particular, gzip and tar play nicely together.

gzip, like zip, uses a variation on the DEFLATE algorithm. However, when used on a tar archive, it'll compress better than zip, because it treats the whole archive together, rather than compressing file-by-file, and thus can look for (and eliminate!) duplication between files as well as within them.

Gzip commands:

  • gzip file.tar
    compresses file.tar to create file.tar.gz.
  • tar czf file.tar.gz mydir/
    archives and compresses mydir/ to create file.tar.gz
  • gunzip file.tar.gz or gzip -d file.tar.gz
    uncompress file.tar.gz.
  • tar zxf file.tar.gz
    uncompress file.tar.gz and also unpack the archive.

Note that you can also use gzcat (use exactly as gunzip) to decompress directly to standard output.


bzip2, like gzip, does compression but not archiving. Again, it works well with tar if you want both archiving and compression. It compresses better than gzip, but the cost of that is that it takes longer to run.

It uses a series of stacked transforms to compress data, the most important of which is the Burrows-Wheeler transform. This reorders blocks to maximise the number of repeated symbols. Runs of repeated symbols can then be replaced by the symbol and a code which represents the length of the run, reducing the size taken up by each run. The Huffman coding used in DEFLATE (where common symbols are swapped in for shorter versions of them) is also used after that, to reduce the space still further, along with a couple of other more minor changes. Given all of that, the time it takes is hardly surprising!

Bzip2 commands:

  • bzip2 file.tar
    compresses file.tar to create file.tar.bz2.
  • bunzip2 file.tbz
    uncompresses file.tbz to create file.tar.
  • tar jxf file.tbz
    uncompresses file.tbz and unpacks the archive.

Note that you can also use bzcat to decompress directly to standard output.

If you're interested in compression algorithms, you could also check out 7-zip (the Linux command-line version is p7zip), which implements the LZM algorithm. In most cases it compresses better than bzip2, and it also decompresses faster (although it compresses slower). However, it's much less popular (I've never seen it in the wild).

Most Popular LinuxPlanet Stories