compress [-cfv] [-b bits] [file ...]
Description
The compress utility reduces the size of the files using adaptive Lempel-Ziv coding. Each file is renamed to the same name plus the extension ".Z". As many of the modification time, access time, file flags, file mode, user ID, and group ID as allowed by permissions are retained in the new file. If compression would not reduce the size of a file, the file is ignored.
If renaming file would cause files to be overwritten and the standard input device is a terminal, the user is prompted (on standard error) for confirmation. If prompting is not possible or confirmation is not received, the files are not overwritten.
Options
Operands
Each file is a pathname of a file to compress. If no files are specified, the standard input is compressed to the standard output. If either the input or output files are not regular files, the checks for reduction in size and file overwriting are not performed, the input file is not removed, and the attributes of the input file are not retained.
Extended Description
The compress utility uses a modified Lempel-Ziv algorithm. Common substrings in the file are first replaced by 9-bit codes 257 and up. When code 512 is reached, the algorithm switches to 10-bit codes and continues to use more bits until the limit specified by the -b flag is reached (the default is 16). Bits must be between 9 and 16.
After the bits limit is reached, compress periodically checks the compression ratio. If it is increasing, compress continues to use the existing code dictionary. However, if the compression ratio decreases, compress discards the table of substrings and rebuilds it from scratch. This allows the algorithm to adapt to the next "block" of the file.
The amount of compression obtained depends on the size of the input, the number of bits per code, and the distribution of common substrings. Typically, text such as source code or English is reduced by 50-60%.
Exit Status
Related information