BSD 4_4 development
[unix-history] / usr / share / man / cat1 / compress.0
CommitLineData
98473598
C
1COMPRESS(1) BSD Reference Manual COMPRESS(1)
2
3N\bNA\bAM\bME\bE
4 c\bco\bom\bmp\bpr\bre\bes\bss\bs, u\bun\bnc\bco\bom\bmp\bpr\bre\bes\bss\bs, z\bzc\bca\bat\bt - compress and expand data
5
6S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
7 c\bco\bom\bmp\bpr\bre\bes\bss\bs [-\b-c\bcf\bfv\bv] [-\b-b\bb _\bb_\bi_\bt_\bs] [_\bf_\bi_\bl_\be _\b._\b._\b.]
8 u\bun\bnc\bco\bom\bmp\bpr\bre\bes\bss\bs [-\b-c\bcf\bfv\bv] [_\bf_\bi_\bl_\be _\b._\b._\b.]
9 z\bzc\bca\bat\bt [_\bf_\bi_\bl_\be _\b._\b._\b.]
10
11D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
12 C\bCo\bom\bmp\bpr\bre\bes\bss\bs reduces the size of the named files using adaptive Lempel-Ziv
13 coding. Each _\bf_\bi_\bl_\be is renamed to the same name plus the extension ``.Z''.
14 As many of the modification time, access time, file flags, file mode, us-
15 er ID, and group ID as allowed by permissions are retained in the new
16 file. If compression would not reduce the size of a _\bf_\bi_\bl_\be, the file is
17 ignored.
18
19 U\bUn\bnc\bco\bom\bmp\bpr\bre\bes\bss\bs restores the compressed files to their original form, renaming
20 the files by deleting the ``.Z'' extension.
21
22 Z\bZc\bca\bat\bt is an alias for ``uncompress -c''.
23
24 If renaming the files would cause files to be overwritten and the stan-
25 dard input device is a terminal, the user is prompted (on the standard
26 error output) for confirmation. If prompting is not possible or confir-
27 mation is not received, the files are not overwritten.
28
29 If no files are specified, the standard input is compressed or uncom-
30 pressed to the standard output. If either the input and output files are
31 not regular files, the checks for reduction in size and file overwriting
32 are not performed, the input file is not removed, and the attributes of
33 the input file are not retained.
34
35 The options are as follows:
36
37 -\b-b\bb Specify the _\bb_\bi_\bt_\bs code limit (see below).
38
39 -\b-c\bc Compressed or uncompressed output is written to the standard out-
40 put. No files are modified.
41
42 -\b-f\bf Force compression of _\bf_\bi_\bl_\be, even if it is not actually reduced in
43 size. Additionally, files are overwritten without prompting for
44 confirmation.
45
46 -\b-v\bv Print the percentage reduction of each file.
47
48 C\bCo\bom\bmp\bpr\bre\bes\bss\bs uses a modified Lempel-Ziv algorithm. Common substrings in the
49 file are first replaced by 9-bit codes 257 and up. When code 512 is
50 reached, the algorithm switches to 10-bit codes and continues to use more
51 bits until the limit specified by the -\b-b\bb flag is reached (the default is
52 16). _\bB_\bi_\bt_\bs must be between 9 and 16.
53
54 After the _\bb_\bi_\bt_\bs limit is reached, c\bco\bom\bmp\bpr\bre\bes\bss\bs periodically checks the com-
55 pression ratio. If it is increasing, c\bco\bom\bmp\bpr\bre\bes\bss\bs continues to use the ex-
56 isting code dictionary. However, if the compression ratio decreases,
57 c\bco\bom\bmp\bpr\bre\bes\bss\bs discards the table of substrings and rebuilds it from scratch.
58 This allows the algorithm to adapt to the next "block" of the file.
59
60 The -\b-b\bb flag is omitted for _\bu_\bn_\bc_\bo_\bm_\bp_\br_\be_\bs_\bs since the _\bb_\bi_\bt_\bs parameter specified
61 during compression is encoded within the output, along with a magic num-
62 ber to ensure that neither decompression of random data nor recompression
63 of compressed data is attempted.
64
65
66
67 The amount of compression obtained depends on the size of the input, the
68 number of _\bb_\bi_\bt_\bs per code, and the distribution of common substrings. Typ-
69 ically, text such as source code or English is reduced by 50-60%. Com-
70 pression is generally much better than that achieved by Huffman coding
71 (as used in the historical command pack), or adaptive Huffman coding (as
72 used in the historical command compact), and takes less time to compute.
73
74 The c\bco\bom\bmp\bpr\bre\bes\bss\bs utility exits 0 on success, and >0 if an error occurs.
75
76S\bSE\bEE\bE A\bAL\bLS\bSO\bO
77 zopen(3)
78
79 Welch, Terry A., "A Technique for High Performance Data Compression",
80 _\bI_\bE_\bE_\bE _\bC_\bo_\bm_\bp_\bu_\bt_\be_\br, 17:6, pp. 8-19, June, 1984.
81
82H\bHI\bIS\bST\bTO\bOR\bRY\bY
83 The c\bco\bom\bmp\bpr\bre\bes\bss\bs command appeared in 4.3BSD.
84
854.3 Berkeley Distribution June 6, 1993 2