Compress (software)

Compression shell command based on the LZW compression algorithm


title: "Compress (software)" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["data-compression-software", "unix-archivers-and-compression-related-utilities", "standard-unix-programs", "unix-sus2008-utilities", "ibm-i-qshell-commands"] description: "Compression shell command based on the LZW compression algorithm" topic_path: "technology/operating-systems" source: "https://en.wikipedia.org/wiki/Compress_(software)" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0

::summary Compression shell command based on the LZW compression algorithm ::

::data[format=table title="Infobox software"]

FieldValue
namecompress / uncompress
authorSpencer Thomas
released
operating systemUnix, Unix-like, IBM i
genreCommand
::

| name = compress / uncompress | logo = | screenshot = | screenshot size = | caption = | author = Spencer Thomas | developer = | released = | latest release version = | latest release date = | operating system = Unix, Unix-like, IBM i | genre = Command | license = | website = | name = compress .Z | extension = .Z | mime = application/x-compress | owner = Spencer Thomas | genre = data compression | website = **compress** is a shell command for compressing data based on the LZW algorithm. **uncompress** is a companion shell command that restores files to their original state (both content and metadata) from a file created with .

Although once popular, has fallen out of favor because it uses the patented LZW algorithm. Its use has been replaced by commands such as [gzip](gzip) and [bzip2](bzip2) that use other algorithms and provide better data compression. Compared to [gzip](gzip) at its fastest setting, is slightly slower at compression, slightly faster at decompression, and has a significantly lower compression ratio. 1.8 MiB of memory is used to compress the Hutter Prize data, slightly more than at its slowest setting.

and have maintained a presence on Unix and BSD systems and have been ported to IBM i.

was standardized in X/Open CAE Specification in 1994, and further in The Open Group Base Specifications, Issue 6 and 7. Linux Standard Base does not require .

is often excluded from the default installation of a Linux distribution but can be installed from a separate package. is available for FreeBSD, OpenBSD, MINIX, Solaris and AIX.

is allowed for Point-to-Point Protocol in and for HTTP/1.1 in , though it is rarely used in modern deployments as the better deflate/gzip is available.

Use

Files compressed by 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](tar-file-format) implementations support compression by piping data through when given the -Z command line option.

can decompress .Z files.

Algorithm

The LZW algorithm used in was patented by Sperry Research Center in 1983. Terry Welch published an IEEE article on the algorithm in 1984, 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 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 and published it as free software to the net.sources USENET group in 1985. was granted in 1985 making unusable without paying royalties to Sperry Research (which later merged into Unisys).

The US LZW patent expired in 2003, so it is now in the public domain in the United States. Today, all LZW patents worldwide are expired (see Graphics Interchange Format#Unisys and LZW patent enforcement).

As of POSIX.1-2024 supports the DEFLATE algorithm used in gzip.

File format

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.

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

References

References

  1. Frysinger, Mike. "ncompress: a public domain project".
  2. Gommans, Luc. "compression - What's the difference between gzip and compress?".
  3. "Large Text Compression Benchmark".
  4. IBM. "IBM System i Version 7.2 Programming Qshell".
  5. [https://pubs.opengroup.org/onlinepubs/009656399/toc.pdf X/Open CAE Specification Commands and Utilities Issue 4, Version 2] (pdf), 1994, opengroup.org
  6. {{man. cu. compress. SUS6
  7. [https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/command.html Chapter 17. Commands and Utilities] in Linux Standard Base Core Specification 5.0.0, linuxfoundation.org
  8. [https://pkgs.org/download/ncompress ncompress], pkgs.org
  9. (2023-02-05). "GNU Gzip".
  10. Welch, Terry A.. (1984). "A technique for high performance data compression". IEEE Computer.
  11. "compress". opengroup.
  12. "compression with 9 bits don't work · Issue #5 · vapier/ncompress".

::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::

data-compression-softwareunix-archivers-and-compression-related-utilitiesstandard-unix-programsunix-sus2008-utilitiesibm-i-qshell-commands