File Compression
From Linux 101, The beginner's guide to all things Linux.
Compressed files in Linux generally exist in one of two similar formats, a gzipped tar, or a bzip2'ed tar. Both of these are actually the combination of two file formats. First, all of the files being compressed are packed into a single .tar file. This tar file is simply a container for multiple files which is not compressed. This tar file is then compressed with either gzip or bzip2. gzip has been the standard for many years, but bzip2 is quickly gaining popularity as it offers better file compression ratios.
You'll notice in all of the examples below that we only appear to be using the `tar' program. This is because after gzip and bzip2 were created, someone modified tar to add support for these file formats. In fact, beyond the examples given below, there are several methods for compressing files into these file formats.
Compressed files of these types will typically have one of the four following appearances:
documents.tar.gz
documents.tgz
documents.tar.bz2
documents.tbz2
The first two are examples of a tar-gzip and the second two are examples of tar-bzip2.
These files can be decompressed with one command.
for the gzip files: tar zxvf documents.tar.gz (or .tgz)
for the bzip2 files: tar jxvf documents.tar.bz2 (or .tbz2)
The parameters for tar specify the compression scheme (z for gzip, j for bzip2), x is the command to extract, v sets verbose mode to print the listing of files being extracted to the screen, and f tells that the filename will follow.
Creating a compressed archive is done in a similar fashion.
tar jcf * stuff.tbz2 will create a tarball of all files in the current directory called stuff.tbz2. As before, z can be substituted for j to use gzip compression instead of bzip2.
You may also encounter various files with only the .gz extention. This means that there is only one file compressed. Many programs have build in gzip support to decompress files on the fly. This is just a convenient way to save space on the harddrive for files that you are less often to use by compressing them and extracting them on the fly, since processor speeds are on the rise.
For more information, try:
-
man tar -
man bzip2 -
man gzip

