The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


compress - compress data


compress [-fv][-b bits][file ...] 

compress [-cfv][-b bits][file] 


The compress utility will attempt to reduce the size of the named files by using adaptive Lempel-Ziv coding. Except when the output is to the standard output, each file will be replaced by one with the extension .Z. If the invoking process has appropriate privileges, the ownership, modes, access time, and modification time of the original file are preserved. If appending the .Z to the filename would make the name exceed {NAME_MAX} bytes, the command will fail. If no files are specified, the standard input will be compressed to the standard output.


The compress utility supports the XBD specification, Utility Syntax Guidelines  .

The following options are supported:

-b bits
Specify the maximum number of bits to use in a code. For a portable application, the bits argument must be:
9 >= bits <= 14

The implementation may allow bits values of greater than 14. The default will be 14, 15 or 16.

Cause compress to write to the standard output; the input file will not be changed, and no .Z files will be created.
Force compression of file, even if it does not actually reduce the size of the file, or if the corresponding file.Z file already exists. If the -f option is not given, and the process is not running in the background, the user will be prompted as to whether an existing file.Z file should be overwritten.
Write the percentage reduction of each file to standard error.


The following operand is supported:
A pathname of a file to be compressed.


The standard input will be used only if no file operands are specified, or if a file operand is "-".


If file operands are specified, the input files contain the data to be compressed.


The following environment variables affect the execution of compress:
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
If set to a non-empty string value, override the values of all the other internationalisation variables.
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments).
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
Determine the location of message catalogues for the processing of LC_MESSAGES .




If no file operands are specified, or if a file operand is "-", or if the -c option is specified, the standard output will contain the compressed output.


Used for all diagnostic and prompt messages and the output from -v.


The output files will contain the compressed output.




The following exit values are returned:
Successful completion.
An error occurred.
One or more files were not compressed because they would have increased in size (and the -f option was not specified).
An error occurred.


The input file will remain unmodified.


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%. Compression is generally much better than that achieved by Huffman coding (as used in pack), or adaptive Huffman coding (compact), and takes less time to compute.

Although compress strictly follows the default actions upon receipt of a signal or when an error occurs, some unexpected results may occur. In some implementations it is likely that a partially compressed file will be left in place, alongside its uncompressed input file. Since the general operation of compress is to delete the uncompressed file only after the .Z file has been successfully filled, an application should always carefully check the exit status of compress before arbitrarily deleting files that have like-named neighbours with .Z suffixes.

Compressed files are not necessarily portable to other systems.

The limit of 14 on the bits option-argument is to achieve portability to all systems (within the restrictions imposed by the lack of an explicit published file format). Some systems based on 16-bit architectures cannot support 15- or 16-bit uncompression.






uncompress, zcat.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]