xref: /original-bsd/usr.bin/compress/compress.1 (revision bd226a66)
1.\" Copyright (c) 1986, 1990 The Regents of the University of California.
2.\" 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.\" %sccs.include.redist.man%
9.\"
10.\"     @(#)compress.1	6.9 (Berkeley) 03/14/91
11.\"
12.Dd
13.Dt COMPRESS 1
14.Os BSD 4.3
15.Sh NAME
16.Nm compress ,
17.Nm uncompress ,
18.Nm zcat
19.Nd compress and expand data
20.Sh SYNOPSIS
21.Nm compress
22.Op Fl f
23.Op Fl v
24.Op Fl c
25.Op Fl b Ar bits
26.Op Ar
27.Nm uncompress
28.Op Fl f
29.Op Fl v
30.Op Fl c
31.Ar
32.Nm zcat
33.Op Ar
34.Sh DESCRIPTION
35.Nm Compress
36reduces the size of the named files using adaptive Lempel-Ziv coding.
37Whenever possible,
38each
39.Ar file
40is replaced by one with the extension
41.Ar \&.Z ,
42while keeping the same ownership modes, access and modification times.
43If no files are specified, the standard input is compressed to the
44standard output.
45Compressed files can be restored to their original form using
46.Nm uncompress
47or
48.Nm zcat
49.Bl -tag -width Ds
50.It Fl f
51Force compression of
52.Ar file ,
53even if it does not actually shrink
54or the corresponding
55.Ar file.Z
56file already exists.
57Except when run in the background under
58.Pa /bin/sh ,
59if
60.Fl f
61is not given the user is prompted as to whether an existing
62.Ar file.Z
63file should be overwritten.
64.It Fl c
65(``cat'').
66.Nm Compress/uncompress
67writes to the standard output; no files are changed.
68The nondestructive behavior of
69.Nm zcat
70is identical to that of
71.Nm uncompress
72.Fl c .
73.It Fl b
74Specify
75.Ar bits
76code limit (see below).
77.It Fl v
78Print the percentage reduction of each file.
79.El
80.Pp
81.Nm Compress
82uses the modified Lempel-Ziv algorithm popularized in
83"A Technique for High Performance Data Compression",
84Terry A. Welch,
85.Em IEEE Computer ,
86vol. 17,
87.no 6
88(June 1984), pp. 8-19.
89Common substrings in the file are first replaced by 9-bit codes 257 and up.
90When code 512 is reached, the algorithm switches to 10-bit codes and
91continues to use more bits until the
92limit specified by the
93.Fl b
94flag is reached (default 16).
95.Ar Bits
96must be between 9 and 16.  The default can be changed in the source to allow
97.Nm compress
98to be run on a smaller machine.
99.Pp
100After the
101.Ar bits
102limit is attained,
103.Nm compress
104periodically checks the compression ratio.  If it is increasing,
105.Nm compress
106continues to use the existing code dictionary.  However,
107if the compression ratio decreases,
108.Nm compress
109discards the table of substrings and rebuilds it from scratch.  This allows
110the algorithm to adapt to the next "block" of the file.
111.Pp
112Note that the
113.Fl b
114flag is omitted for
115.Ar uncompress
116since the
117.Ar bits
118parameter specified during compression
119is encoded within the output, along with
120a magic number to ensure that neither decompression of random data nor
121recompression of compressed data is attempted.
122.Pp
123.ne 8
124The amount of compression obtained depends on the size of the
125input, the number of
126.Ar bits
127per code, and the distribution of common substrings.
128Typically, text such as source code or English
129is reduced by 50\-60%.
130Compression is generally much better than that achieved by
131Huffman coding (as used in the historical command
132pack),
133or adaptive Huffman coding (as
134used in the historical command
135compact),
136and takes less time to compute.
137.Pp
138If an error occurs, exit status is 1;
139if the last file was not compressed because it became larger, the status
140is 2; otherwise the status is 0.
141.Sh DIAGNOSTICS
142.Bl -tag -width 4n
143.It "Usage: compress [-fvc] [-b maxbits] [file ...]"
144Invalid options were specified on the command line.
145.It "Missing maxbits"
146Maxbits must follow
147.Fl b .
148.It Ar file : No "not in compressed format"
149The file specified to
150.Ar uncompress
151has not been compressed.
152.It Xo
153.Ar file : No "compressed with"
154.Ar \&xx No "bits, can only handle" Ar \&yy No bits
155.Xc
156.Ar File
157was compressed by a program that could deal with
158more
159.Ar bits
160than the compress code on this machine.
161Recompress the file with smaller
162.Ar bits .
163.It Ar file : No "already has .Z suffix -- no change"
164The file is assumed to be already compressed.
165Rename the file and try again.
166.It Ar file : No "filename too long to tack on .Z"
167The file cannot be compressed because its name is longer than
16812 characters.
169Rename and try again.
170This message does not occur on BSD systems.
171.It Ar file No "already exists; do you wish to overwrite (y or n)?"
172Respond "y" if you want the output file to be replaced; "n" if not.
173.It "uncompress: corrupt input"
174A
175.Dv SIGSEGV
176violation was detected which usually means that the input file is
177corrupted.
178.It Compression: Em "xx.xx%"
179Percentage of the input saved by compression.
180(Relevant only for
181.Fl v . )
182.It "-- not a regular file: unchanged"
183When the input file is not a regular file,
184(e.g. a directory), it is
185left unaltered.
186.It "-- has" Ar xx No "other links: unchanged"
187The input file has links; it is left unchanged.  See
188.Xr ln 1
189for more information.
190.It "-- file unchanged"
191No savings is achieved by
192compression.  The input remains virgin.
193.El
194.Sh FILES
195.Bl -tag -width file.Z
196.It Pa file.Z
197compressed file is file.Z
198.El
199.Sh BUGS
200Although compressed files are compatible between machines with large memory,
201.Fl b Ns Ar 12
202should be used for file transfer to architectures with
203a small process data space (64KB or less, as exhibited by the
204.Tn DEC PDP
205series, the Intel 80286, etc.)
206.Pp
207.Nm Compress
208should be more flexible about the existence of the `.Z' suffix.
209.Sh HISTORY
210The
211.Nm
212command appeared in
213.Bx 4.3 .
214