xref: /netbsd-src/usr.bin/compress/compress.1 (revision 99a393ce510b9a9244e16a9c11222233474c8498)
1.\"	$NetBSD: compress.1,v 1.16 2017/07/04 06:58:55 wiz Exp $
2.\"
3.\" Copyright (c) 1986, 1990, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" James A. Woods, derived from original work by Spencer Thomas
8.\" and Joseph Orost.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)compress.1	8.2 (Berkeley) 4/18/94
35.\"
36.Dd January 23, 2003
37.Dt COMPRESS 1
38.Os
39.Sh NAME
40.Nm compress ,
41.\".Nm uncompress ,
42.Nm uncompress
43.\".Nm zcat
44.Nd compress and expand data
45.Sh SYNOPSIS
46.Nm
47.Op Fl cdfv
48.Op Fl b Ar bits
49.Op Ar
50.Nm uncompress
51.Op Fl cdfv
52.Op Ar
53.\".Nm zcat
54.\".Op Ar
55.Sh DESCRIPTION
56.Nm
57reduces the size of the named files using adaptive Lempel-Ziv coding.
58Each
59.Ar file
60is renamed to the same name plus the extension
61.Dq .Z .
62As many of the modification time, access time, file flags, file mode,
63user ID, and group ID as allowed by permissions are retained in the
64new file.
65If compression would not reduce the size of a
66.Ar file ,
67the file is ignored.
68.Pp
69.Nm uncompress
70restores the compressed files to their original form, renaming the
71files by deleting the
72.Dq .Z
73extension.
74.\".Pp
75.\".Nm Zcat
76.\"is an alias for
77.\".Dq "uncompress -c" .
78.Pp
79If renaming the files would cause files to be overwritten and the standard
80input device is a terminal, the user is prompted (on the standard error
81output) for confirmation.
82If prompting is not possible or confirmation is not received, the files
83are not overwritten.
84.Pp
85If no files are specified, the standard input is compressed or uncompressed
86to the standard output.
87If either the input and output files are not regular files, the checks for
88reduction in size and file overwriting are not performed, the input file is
89not removed, and the attributes of the input file are not retained.
90.Pp
91The options are as follows:
92.Bl -tag -width Ds
93.It Fl b
94Specify the
95.Ar bits
96code limit (see below).
97.It Fl c
98Compressed or uncompressed output is written to the standard output.
99No files are modified.
100.It Fl d
101Force decompression.
102.It Fl f
103Force compression of
104.Ar file ,
105even if it is not actually reduced in size.
106Additionally, files are overwritten without prompting for confirmation.
107.It Fl v
108Print the percentage reduction of each file.
109.El
110.Pp
111.Nm
112uses a modified Lempel-Ziv algorithm.
113Common substrings in the file are first replaced by 9-bit codes 257 and up.
114When code 512 is reached, the algorithm switches to 10-bit codes and
115continues to use more bits until the
116limit specified by the
117.Fl b
118flag is reached (the default is 16).
119.Ar Bits
120must be between 9 and 16.
121.Pp
122After the
123.Ar bits
124limit is reached,
125.Nm
126periodically checks the compression ratio.
127If it is increasing,
128.Nm
129continues to use the existing code dictionary.
130However, if the compression ratio decreases,
131.Nm
132discards the table of substrings and rebuilds it from scratch.
133This allows the algorithm to adapt to the next "block" of the file.
134.Pp
135The
136.Fl b
137flag is omitted for
138.Ar uncompress
139since the
140.Ar bits
141parameter specified during compression
142is encoded within the output, along with
143a magic number to ensure that neither decompression of random data nor
144recompression of compressed data is attempted.
145.Pp
146The amount of compression obtained depends on the size of the
147input, the number of
148.Ar bits
149per code, and the distribution of common substrings.
150Typically, text such as source code or English is reduced by 50\-60%.
151Compression is generally much better than that achieved by Huffman
152coding (as used in the historical command pack), or adaptive Huffman
153coding (as used in the historical command compact), and takes less
154time to compute.
155.Sh EXIT STATUS
156.Ex -std compress
157.Sh SEE ALSO
158.Xr zcat 1
159.Rs
160.%A Welch, Terry A.
161.%D June, 1984
162.%T "A Technique for High Performance Data Compression"
163.%J "IEEE Computer"
164.%V 17:6
165.%P pp. 8-19
166.Re
167.Sh HISTORY
168The
169.Nm
170command appeared in
171.Bx 4.3 .
172