compress is a shellcommand for compressing data based on the LZW algorithm.[1]uncompress is a companion shell command that restores files to their original state (both content and metadata) from a file created with compress.
Although once popular, compress has fallen out of favor because it uses the patented LZW algorithm. Its use has been replaced by commands such as gzip and bzip2 that use other algorithms and provide better data compression. Compared to gzip at its fastest setting, compress is slightly slower at compression, slightly faster at decompression, and has a significantly lower compression ratio.[2] 1.8 MiB of memory is used to compress the Hutter Prize data, slightly more than gzip at its slowest setting.[3]
compress and uncompress have maintained a presence on Unix and BSD systems and have been ported to IBM i.[4]
compress was standardized in X/Open CAE Specification in 1994,[5] and further in The Open Group Base Specifications, Issue 6 and 7.[6]Linux Standard Base does not require compress.[7]
compress is often excluded from the default installation of a Linux distribution but can be installed from a separate package.[8]compress is available for FreeBSD, OpenBSD, MINIX, Solaris and AIX.
Files compressed by compress are typically named with extension ".Z" and therefore sometimes called .Z files. The extension derives from the earlier pack program which used extension ".z".
Most tar implementations support compression by piping data through compress when given the -Z command line option.
The LZW algorithm used in compress was patented by Sperry Research Center in 1983. Terry Welch published an IEEE article on the algorithm in 1984,[10] but failed to note that he had applied for a patent on the algorithm. Spencer Thomas of the University of Utah took this article and implemented compress in 1984, without realizing that a patent was pending on the LZW algorithm. The GIF image format also incorporated LZW compression in this way, and Unisys later claimed royalties on implementations of GIF. Joseph M. Orost led the team and worked with Thomas et al. to create the final (4.0) version of compress and published it as free software to the net.sources USENET group in 1985. U.S. patent 4,558,302 was granted in 1985 – making compress unusable without paying royalties to Sperry Research (which later merged into Unisys).
The compressed output consists of bit groups. Each bit group consists of codes with fixed amount of bits (9–16). Each group, except the last group, is aligned to the number of bits per code multiplied by 8 and right padded with zeroes. The last group is aligned to 8 bit octets and padded with zeroes. More information can be found at an issue on the ncompress GitHub repository.[12]
Example:
Suppose the output has ten 9-bit codes, five 10-bit codes, and thirteen 11-bit codes. There are three groups to output containing 90 bits, 50 bits, and 143 bits of data.
First group will be 90 bits of data + 54 zero bits of padding in order to be aligned to 72 bits (9 bits × 8).
Second group will be 50 bits of data + 30 zero bits of padding in order to be aligned to 80 bits (10 bits × 8).
Third group will be 143 bits of data + 1 zero bit of padding in order to be aligned to 8 bits (since this is the last group in the output).
The existence of padding bits is actually a bug, as LZW does not require any alignment. This bug existed for more than 35 years and was in the original UNIX compress, ncompress, gzip and the Windows port. All application/x-compress files were created using this bug.
Some compress implementations write random bits from uninitialized buffer in paddings. There is no guarantee that the paddings will be zeroes. The decompressor must ignore the values in the paddings for compatibility.
^Frysinger, Mike. "ncompress: a public domain project". Retrieved 2014-07-30. Compress is a fast, simple LZW file compressor. Compress does not have the highest compression rate, but it is one of the fastest programs to compress data. Compress is the de facto standard in the UNIX community for compressing files.
^"GNU Gzip". The GNU Operating System and the Free Software Movement. 2023-02-05. Retrieved 2024-04-03. gunzip can currently decompress files created by gzip, zip, compress or pack. The detection of the input format is automatic.