File Compression
Compressing Files
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>.gz |
zip |
zip <newfile> <oldfile> |
<newfile>.zip |
compress |
compress <filename> |
<filename>.Z |
pack |
pack <filename> |
<filename>.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>.gz |
<filename> |
unzip |
unzip <filename>.zip |
<filename> |
uncompress |
uncompress <filename>.Z |
<filename> |
unpack |
unpack <filename>.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>
or
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
Last updated:
February 03, 2011