Unix: Packaging

Compression

Compress commands (gzip, gunzip, zcat)

The command gzip compresses a file to reduce the space needed to store it. This conserves disk space. The compression is loss-less, meaning that no information is lost in the process. Companion programs are gunzip to undo the compression and restore the file to its original size, and zcat, to let you view the contents of compressed files without having to uncompress first.

The following sequence of commands checks the size of the file unixpast.txt, the compresses it, checks the size again, output the content of the compressed file to the screen, and finally restore it to its original size.

$ ls -l unixpast.txt
-rw-r--r-- 1 john staff   7786 2012-10-15 08:16 unixpast.txt
$ gzip unixpast.txt
$ ls -l unixpast.txt.gz
-rw-r--r-- 1 john staff   3548 2012-10-15 08:16 unixpast.txt.gz
$ zcat unixpast.txt.gz
…
$ gunzip unixpast.txt.gz

Exercise

Try out all the commands described above on the file unixpast.txt. Make a note of file sizes and compute the compression ratio using the formula:

compression ratio = compressed size / compressed size

If the text scrolls too fast for you when you try out the zcat command, pipe the output though less.

Scripting (make)

[TBA]

Packing and unpacking (tar)

[TBA]

Summary

Command Meaning
gzip compress file to reduce file space
gunzip expand compressed file
zcat expand compress file and print it stdout