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