File Compression

There are several commands available to compress files. Four of these commands are gzip, zip, compress and pack. These commands use different compression algorithms, take different amounts of time, and reduce files by different amounts. In general, these commands can reduce the size of a file by 50-75%.

Command Syntax File Produced
gzip gzip <filename> <filename&gt.gz
zip zip <newfile> <oldfile> <newfile&
compress compress <filename> <filename&gt.Z
pack pack <filename> <filename&gt.z

Decompressing Files

It is best to use the same utility to decompress a file that was used to compress it. However, sometimes
it is not possible to tell which utility was used to compress a file. In these situations, try using
gunzip. The gunzip command can decompress files in almost any format.

Command Syntax File Produced
gunzip gunzip <filename&gt.gz <filename>
unzip unzip <filename& <filename>
uncompress uncompress <filename&gt.Z <filename>
unpack unpack <filename&gt.z <filename>

Viewing Compressed Files

There are two commands you can use to view a compressed file without decompressing it. The zcat command will print a compressed file to the standard output. The zcat command will work on a file compressed using any of the above commands. The syntax is:

    zcat <filename>

The zmore command will display a compressed file one screen at a time. The
zmore command will work on a file compressed using any of the above commands. The syntax is:

    zmore <filename>

Executing Compresses Files

The gzexe utility allows you to compress executables in place and have them
automatically decompress and execute when you run them (at a penalty in performance). The syntax is:

    gzexe <filename>

This will produce a compressed executable file with the exact same name as the original file. To
decompress the executable file, type:

    gzexe -d <filename>

Comparing Compressed Files

You can compare two compressed files using the zcmp and zdiff commands. The syntax is:

    zcmp <filename1> <filename2>
    zdiff <filename1> <filename2>

Searching Compressed Files

You can search a compressed file for a regular expression using the zgrep
command. The syntax is:

    zgrep <pattern> <filename>
    Example: zgrep freud essay1.gz