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