compress reduces the size of files using adaptive Lempel-Ziv coding: recurrent strings in the text are reduced to unique codes ranging from 9 to a maximum of 16 bits.
If the calling process has the appropriate privileges, the owner, access permissions, and the dates of last access and modification of the specified files remain the same.
Each specified file is replaced by a file with the same basename plus a .Z extension.
The amount of compression obtained depends on the size of the input file, the value of bits (see option -b below), and the distribution of recurrent substrings. Typically, files containing only text or source code are reduced by 50-60%. Compression achieved with the Lempel-Ziv approach is generally much better than that achieved with Huffman coding, and takes less time to compute.
No compression is performed if
the input file is not a regular file (if it is a directory, for example)
there are other links to the input file
the input file already has a .Z extension
the .Z file to be created already exists, and compress is being executed in the
backgroundno savings can be achieved by compression
Files compressed with compress can be decompressed with uncompress.
zcat produces uncompressed output on the standard output, but leaves the compressed file intact.
Syntax
Format 1: |
compress[ -fv][ -b bits][ file ...] |
Format 2: |
compress[ -cfv][ -b bits][ file] |
No option specified: The specified files are compressed if storage space can be saved as a result.
Simply writes the output of compress to standard output without modifying or creating any files. Only one file is allowed with -c.
(f - force) Forces compression even if no space savings will be achieved or the .Z file that will be created already exists. If the .Z file already exists it will be overwritten. -f not specified:
(verbose) Displays the percentage reduction for each file compressed:
Sets the upper limit (in bits) for recurrent substring codes to bits. The value for bits must be between 9 and 16. Lowering the number of bits will result in larger, less compressed files. The bits parameter specified during compression is encoded within the compressed file, together with a magic number to ensure that it is impossible to further compress a file which is already compressed. -b not specified: The value of bits defaults to 16. Caution!
Name of the file to be compressed. You may specify more than one file. If you specify a hyphen (-) for one of the files, compress will read that file from standard input. file must not be a directory, and there must be no other links to it. The compressed file is assigned the name file.Z, and the named file is deleted after successful compression. file.Z has the same access permissions, access time and modification time as file. The maximum length of the name of file depends on the file system being used. The maximum allowable length is equal to the maximum file name length supported by the file system, minus 2 characters. This allows for the extension to file.Z. If this length is exceeded, file will not be compressed. file not specified or specified as a hyphen (–): |
Exit status
0 | Compression successful |
1 | Error |
2 | Compression of one or more files not performed, as it would have increased the size of the file. |
>2 | Error |
Error
file file file file |
Locale
The following environment variables affect the execution of compress: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE 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). LC_CTYPE governs character classes, character conversion (shifting) and the behavior of character classes in regular expressions. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example
The file films, which occupies 4862 bytes in uncompressed form, is to be compressed.
|
See also
uncompress, zcat |