Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

compress - compress files

&pagelevel(4)&pagelevel

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
    background

  • no 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.

-c

Simply writes the output of compress to standard output without modifying or creating any files. Only one file is allowed with -c.

-f

(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:
compress prompts to verify whether an existing .Z file should be overwritten. No prompt is issued if compress is running in the background.

-v

(verbose)

Displays the percentage reduction for each file compressed:

file Compression: xx . xx % –– replaced with file .Z

-b bits

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!
Although compressed files are compatible between machines with large memory, the -b 12 option should be used for file transfer to architectures with a small process data space (64 Kbyte or less).


file

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 (–):
Data from standard input is written in compressed form to standard output.

Exit status

0Compression successful
1Error
2Compression of one or more files not performed, as it would have increased the size of the file.
>2Error

Error

file : filename too long to tack on .Z
The name of the compressed file is too long. No compression takes place.


file -- not a regular file: unchanged
If the input file is not a regular file it is left uncompressed.


file : -- has xx other links: unchanged
The input file has xx other links; it is left uncompressed.


file unchanged
No savings can be achieved by compression. The input file remains uncompressed. The -f option can be used to force compression.

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.

$ ls -l
total 10

-rw-------  1  FELIX    group1    4862 Aug 19 09:27 films

$ compress -v films
compress: filme: 50.78% Compression -- replaced with films.Z

$ ls -l

total 6

-rw-------  1  FELIX    group1    2393 Aug 19 09:27 films.Z

See also

uncompress, zcat