File Compression and Decompression in Unix

In this tutorial I cover how to compress and decompress files in Unix shell. The Unix equivalent of file compression command is gzip and gunzip is used to unzip the file. These commands are GNU flavors of compression techniques, hence the 'g' is prefix to zip and unzip. These are available with Linux and SunOS.

$ gzip filename
The above command creates a compressed file with the name filename.gz. Note that the original file (filename) no longer exists after successful execution of this command. The default file extension of the compressed file is .gz

Below shown is the example:

$ gunzip filename
The above command decompresses the compressed file. The compressed file with .gz extension will no longer exist after successful execution of this command. If the decompressed file already exists, this command will overwrite the file.

Below shown is the example:

Reading compressed files (available with Linux flavours)
zmore and zcat can be used to read compressed files.

The examples are shown as below.