UC San Diego SearchMenu

Compress and Uncompress -- the Archive Utilities

Compress is a utility program that can greatly reduce the amount of disk space your files are occupying. To achieve this, it encodes your files in such a way that you must uncompress the file, or use a special utility, to read the original data.

To compress a file (or files), use one the following commands:

% compress filename
% compress file1 file2 file3 ...

A compressed file has a .Z suffix added to it. Because of the way compress functions, the .Z files are not human-readable. To restore the file to its original, usable state, use the uncompress command:

% uncompress filename

Uncompress will automatically look for a file of that name that has the .Z suffix, decode it, and restore the original name.

Taking a look

The zcat command will write the decoded version of a compressed file to the standard output. This means you can take a quick look at an encoded file without uncompressing it. The following command will display the (normal version of the) encoded file one page at a time:

% zcat datafile.Z | more

Common problems

To ensure the safety of your data during the encoding process, compress does not remove the original file until the compressed file is complete. This means, however, that in order to compress a file, you need the disk space required to store both the original and encoded versions simultaneously. If in doubt, try. If the compress command resulted in a .Z file, you can be sure it worked; compress will never leave a partially completed .Z file.

In the event that you are trying to use compress and run out of disk quota, you could move the files to the /tmp directory and perform the compression there. For example, the following commands will compress the file "foobar", even though the you may be hard up against your quota limit.

% mv foobar /tmp            (move the file to /tmp)
% compress /tmp/foobar      (compress it there)
% mv /tmp/foobar.Z .        (move it back--and that last
                            period IS important)

More info

There is a man page for compress. Type "man compress" from the unix prompt.