Contents

gzip compresses files. Each single file is compressed into a single file. The compressed file consists of a GNU zip header and deflated data.

If given a file as an argument, gzip compresses the file, adds a ".gz" suffix, and deletes the original file. With no arguments, gzip compresses the standard input and writes the compressed file to standard output.

gunzip uncompresses a file that was compressed with "gzip" or "compress". It tries to handle both the GNU zip format of gzip and the older Unix compress format. It does this by recognizing the extension (".gz" or ".Z" or several others) of a file.

Some useful options are:

-c Write uncompressed data to stdout. Do not delete original file.

Undo the effect of gzip README.gz by replacing the compressed version of the file with the original, uncompressed version. Creates README and deletes README.gz.

$ gunzip README.gz

Write the uncompressed contents of README.gz to standard output. Pipe it into a pager for easy reading of a compressed file.

There are two different conventions concerning gzipped tarballs. One often encounters .tar.gz. The other popular choice is .tgz. Slackware packages use the latter convention.

If you have access to a tape device or other backup medium, then you can use it instead of an archive file. If the material to be archived exceeds the capacity of the backup medium, the program will prompt the user to insert a new tape or diskette.

Use the following command to back up the myfiles directory to floppies:

$ tar -cvf /dev/fd0 myfiles

Restore that backup with:

$ tar -xvf /dev/fd0

You can also specify standard input or output -f - instead of an archive file or device. It is possible to use copy between directories by piping two "tar" commands together. For example, suppose we have two directories, from-stuff and to-stuff

$ ls -F
from-stuff/
to-stuff/

As described in Running Linux, one can mirror everything from from-stuff to to-stuff this way:

cpio is used for creating archives. When creating an archive, a list of files is fed to its standard-input (rather than specifying the files on the commandline). This file-list is typically created by ls, find or locate and then piped directly to cpio; but it can also first be filtered/edited with commands like *grep, sed, sort and others. A (pre-edited) list stored as a file can also be used, by using cat to feed the pipeline or simply by redirecting the shell's standard-input (<).

cpio works in one of three modes:

cpio -o - Copy-Out mode: Files are copied out from the filesystem to create an archive. Usually the archive is created by simply using the shell to redirect cpio's output to a file (with >).

cpio -i - Copy-In mode: Files from an existing archive are restored/extracted, and copied back in to the filesystem.

cpio -p - Pass-Through mode: cpio is used to copy files from one location in the directory-tree to another, without an actual archiving being made.

In addition comes:

cpio -t - List archive: The content of an archive is listed without extracting it.

bzip2 and bunzip2 are similar to "gzip"/"gunzip" but with a different compression method. Compression is generally better but slower than "gzip". Decompression is somewhat fast.

An option of -1 through -9 can be used to specify how good bzip2 should compress. The number tells how large "chunks" in steps of 100kB should compress at a time, so using bzip2 -5 foo.bar will compress foo.bar in chunks of 500kB each. Generally, larger chunks means better compression (but probably slower). Only undamaged "chunks" can be recovered with bzip2recover from a damaged bzip2-file, so if you've compressed 900kB chunks, you'll loose 900kB of your file if one chunk is damaged - but only 100kB if you used 100kB chunks (bzip2 -1). By default bzip2 uses 900kB chunks for best possible compression.

zip is an archive which compresses the members individually. (Imagine gzip of every file before tar-ing them, but with a different format.) The "zip" format is a common archiving file format used on Microsoft Windows PCs.

Like for gzip the quality of the compression can be specified by giving a number between 1 and 9 as an option (e.g. zip -5). 1 is quickest, but gives a low-quality compression. 9 gives the highest quality of compression, but is slow. In addition 0 can be used (i.e. zip -0) to specify that the files should just be "stored" and not compressed (a compression of 0%), thus making it possible to use zip to make uncompressed archives.

Note that a zip-archive contains individualy compressed files collected into a single file. This is the opposite of how it's done for most other compressed Unix-archives (e.g. tar.gz and tar.bz2), where the files/directories are first collected into a single file -- an archive (e.g. cpio or tar), and then this single file is compressed (e.g. using gzip or bzip2).