Compressing files using the compress command

Use the compress command to reduce the size of files using adaptive Lempel-Zev coding.

Each original file specified by the File parameter is replaced by a compressed file with a .Z appended to its name. The compressed file retains the same ownership, modes, and access and modification times of the original file. If no files are specified, the standard input is compressed to the standard output. If compression does not reduce the size of a file, a message is written to standard error and the original file is not replaced.

Use the uncompress command to restore compressed files to their original form.

The amount of compression depends on the size of the input, the number of bits per code specified by the Bits variable, and the distribution of common substrings. Typically, source code or English text is reduced by 50 to 60 percent. The compression of the compress command is generally more compact and takes less time to compute than the compression achieved by the pack command, which uses adaptive Huffman coding.

For example, to compress the foo file and write the percentage compression to standard error, type the following:
compress -v foo