Move bzip2 to archiver category
[unleashed-userland.git] / components / archiver / bzip2 / manpages / bzip2.1
blob9e1eeda632d72a315c6feaa92d6a5f849edbb7ae
1 .\"
2 .PU
3 .TH bzip2 1
4 .SH NAME
5 bzip2, bunzip2 \- a block-sorting file compressor, v1.0.6
6 .br
7 bzcat \- decompresses files to stdout
8 .br
9 bzip2recover \- recovers data from damaged bzip2 files
11 .SH SYNOPSIS
12 .ll +8
13 .B bzip2
14 .RB [ " \-cdfkqstvzVL123456789 " ]
16 .I "filenames \&..."
18 .ll -8
19 .br
20 .B bunzip2
21 .RB [ " \-fkvsVL " ]
22
23 .I "filenames \&..."
25 .br
26 .B bzcat
27 .RB [ " \-s " ]
28
29 .I "filenames \&..."
31 .br
32 .B bzip2recover
33 .I "filename"
35 .SH DESCRIPTION
36 .I bzip2
37 compresses files using the Burrows-Wheeler block sorting
38 text compression algorithm, and Huffman coding.  Compression is
39 generally considerably better than that achieved by more conventional
40 LZ77/LZ78-based compressors, and approaches the performance of the PPM
41 family of statistical compressors.
43 The command-line options are deliberately very similar to 
44 those of 
45 .I GNU gzip, 
46 but they are not identical.
48 .I bzip2
49 expects a list of file names to accompany the
50 command-line flags.  Each file is replaced by a compressed version of
51 itself, with the name "original_name.bz2".  
52 Each compressed file
53 has the same modification date, permissions, and, when possible,
54 ownership as the corresponding original, so that these properties can
55 be correctly restored at decompression time.  File name handling is
56 naive in the sense that there is no mechanism for preserving original
57 file names, permissions, ownerships or dates in filesystems which lack
58 these concepts, or have serious file name length restrictions, such as
59 MS-DOS.
61 .I bzip2
62 and
63 .I bunzip2
64 will by default not overwrite existing
65 files.  If you want this to happen, specify the \-f flag.
67 If no file names are specified,
68 .I bzip2
69 compresses from standard
70 input to standard output.  In this case,
71 .I bzip2
72 will decline to
73 write compressed output to a terminal, as this would be entirely
74 incomprehensible and therefore pointless.
76 .I bunzip2
77 (or
78 .I bzip2 \-d) 
79 decompresses all
80 specified files.  Files which were not created by 
81 .I bzip2
82 will be detected and ignored, and a warning issued.  
83 .I bzip2
84 attempts to guess the filename for the decompressed file 
85 from that of the compressed file as follows:
87        filename.bz2    becomes   filename
88        filename.bz     becomes   filename
89        filename.tbz2   becomes   filename.tar
90        filename.tbz    becomes   filename.tar
91        anyothername    becomes   anyothername.out
93 If the file does not end in one of the recognised endings, 
94 .I .bz2, 
95 .I .bz, 
96 .I .tbz2
98 .I .tbz, 
99 .I bzip2 
100 complains that it cannot
101 guess the name of the original file, and uses the original name
102 with
103 .I .out
104 appended.
106 As with compression, supplying no
107 filenames causes decompression from 
108 standard input to standard output.
110 .I bunzip2 
111 will correctly decompress a file which is the
112 concatenation of two or more compressed files.  The result is the
113 concatenation of the corresponding uncompressed files.  Integrity
114 testing (\-t) 
115 of concatenated 
116 compressed files is also supported.
118 You can also compress or decompress files to the standard output by
119 giving the \-c flag.  Multiple files may be compressed and
120 decompressed like this.  The resulting outputs are fed sequentially to
121 stdout.  Compression of multiple files 
122 in this manner generates a stream
123 containing multiple compressed file representations.  Such a stream
124 can be decompressed correctly only by
125 .I bzip2 
126 version 0.9.0 or
127 later.  Earlier versions of
128 .I bzip2
129 will stop after decompressing
130 the first file in the stream.
132 .I bzcat
134 .I bzip2 -dc) 
135 decompresses all specified files to
136 the standard output.
138 .I bzip2
139 will read arguments from the environment variables
140 .I BZIP2
142 .I BZIP,
143 in that order, and will process them
144 before any arguments read from the command line.  This gives a 
145 convenient way to supply default arguments.
147 Compression is always performed, even if the compressed 
148 file is slightly
149 larger than the original.  Files of less than about one hundred bytes
150 tend to get larger, since the compression mechanism has a constant
151 overhead in the region of 50 bytes.  Random data (including the output
152 of most file compressors) is coded at about 8.05 bits per byte, giving
153 an expansion of around 0.5%.
155 As a self-check for your protection, 
156 .I 
157 bzip2
158 uses 32-bit CRCs to
159 make sure that the decompressed version of a file is identical to the
160 original.  This guards against corruption of the compressed data, and
161 against undetected bugs in
162 .I bzip2
163 (hopefully very unlikely).  The
164 chances of data corruption going undetected is microscopic, about one
165 chance in four billion for each file processed.  Be aware, though, that
166 the check occurs upon decompression, so it can only tell you that
167 something is wrong.  It can't help you 
168 recover the original uncompressed
169 data.  You can use 
170 .I bzip2recover
171 to try to recover data from
172 damaged files.
174 Return values: 0 for a normal exit, 1 for environmental problems (file
175 not found, invalid flags, I/O errors, &c), 2 to indicate a corrupt
176 compressed file, 3 for an internal consistency error (eg, bug) which
177 caused
178 .I bzip2
179 to panic.
181 .SH OPTIONS
183 .B \-c --stdout
184 Compress or decompress to standard output.
186 .B \-d --decompress
187 Force decompression.  
188 .I bzip2, 
189 .I bunzip2 
191 .I bzcat 
193 really the same program, and the decision about what actions to take is
194 done on the basis of which name is used.  This flag overrides that
195 mechanism, and forces 
196 .I bzip2
197 to decompress.
199 .B \-z --compress
200 The complement to \-d: forces compression, regardless of the
201 invocation name.
203 .B \-t --test
204 Check integrity of the specified file(s), but don't decompress them.
205 This really performs a trial decompression and throws away the result.
207 .B \-f --force
208 Force overwrite of output files.  Normally,
209 .I bzip2 
210 will not overwrite
211 existing output files.  Also forces 
212 .I bzip2 
213 to break hard links
214 to files, which it otherwise wouldn't do.
216 bzip2 normally declines to decompress files which don't have the
217 correct magic header bytes.  If forced (-f), however, it will pass
218 such files through unmodified.  This is how GNU gzip behaves.
220 .B \-k --keep
221 Keep (don't delete) input files during compression
222 or decompression.
224 .B \-s --small
225 Reduce memory usage, for compression, decompression and testing.  Files
226 are decompressed and tested using a modified algorithm which only
227 requires 2.5 bytes per block byte.  This means any file can be
228 decompressed in 2300k of memory, albeit at about half the normal speed.
230 During compression, \-s selects a block size of 200k, which limits
231 memory use to around the same figure, at the expense of your compression
232 ratio.  In short, if your machine is low on memory (8 megabytes or
233 less), use \-s for everything.  See MEMORY MANAGEMENT below.
235 .B \-q --quiet
236 Suppress non-essential warning messages.  Messages pertaining to
237 I/O errors and other critical events will not be suppressed.
239 .B \-v --verbose
240 Verbose mode -- show the compression ratio for each file processed.
241 Further \-v's increase the verbosity level, spewing out lots of
242 information which is primarily of interest for diagnostic purposes.
244 .B \-L --license -V --version
245 Display the software version, license terms and conditions.
247 .B \-1 (or \-\-fast) to \-9 (or \-\-best)
248 Set the block size to 100 k, 200 k ..  900 k when compressing.  Has no
249 effect when decompressing.  See MEMORY MANAGEMENT below.
250 The \-\-fast and \-\-best aliases are primarily for GNU gzip 
251 compatibility.  In particular, \-\-fast doesn't make things
252 significantly faster.  
253 And \-\-best merely selects the default behaviour.
255 .B \--
256 Treats all subsequent arguments as file names, even if they start
257 with a dash.  This is so you can handle files with names beginning
258 with a dash, for example: bzip2 \-- \-myfilename.
260 .B \--repetitive-fast --repetitive-best
261 These flags are redundant in versions 0.9.5 and above.  They provided
262 some coarse control over the behaviour of the sorting algorithm in
263 earlier versions, which was sometimes useful.  0.9.5 and above have an
264 improved algorithm which renders these flags irrelevant.
266 .SH MEMORY MANAGEMENT
267 .I bzip2 
268 compresses large files in blocks.  The block size affects
269 both the compression ratio achieved, and the amount of memory needed for
270 compression and decompression.  The flags \-1 through \-9
271 specify the block size to be 100,000 bytes through 900,000 bytes (the
272 default) respectively.  At decompression time, the block size used for
273 compression is read from the header of the compressed file, and
274 .I bunzip2
275 then allocates itself just enough memory to decompress
276 the file.  Since block sizes are stored in compressed files, it follows
277 that the flags \-1 to \-9 are irrelevant to and so ignored
278 during decompression.
280 Compression and decompression requirements, 
281 in bytes, can be estimated as:
283        Compression:   400k + ( 8 x block size )
285        Decompression: 100k + ( 4 x block size ), or
286                       100k + ( 2.5 x block size )
288 Larger block sizes give rapidly diminishing marginal returns.  Most of
289 the compression comes from the first two or three hundred k of block
290 size, a fact worth bearing in mind when using
291 .I bzip2
292 on small machines.
293 It is also important to appreciate that the decompression memory
294 requirement is set at compression time by the choice of block size.
296 For files compressed with the default 900k block size,
297 .I bunzip2
298 will require about 3700 kbytes to decompress.  To support decompression
299 of any file on a 4 megabyte machine, 
300 .I bunzip2
301 has an option to
302 decompress using approximately half this amount of memory, about 2300
303 kbytes.  Decompression speed is also halved, so you should use this
304 option only where necessary.  The relevant flag is -s.
306 In general, try and use the largest block size memory constraints allow,
307 since that maximises the compression achieved.  Compression and
308 decompression speed are virtually unaffected by block size.
310 Another significant point applies to files which fit in a single block
311 -- that means most files you'd encounter using a large block size.  The
312 amount of real memory touched is proportional to the size of the file,
313 since the file is smaller than a block.  For example, compressing a file
314 20,000 bytes long with the flag -9 will cause the compressor to
315 allocate around 7600k of memory, but only touch 400k + 20000 * 8 = 560
316 kbytes of it.  Similarly, the decompressor will allocate 3700k but only
317 touch 100k + 20000 * 4 = 180 kbytes.
319 Here is a table which summarises the maximum memory usage for different
320 block sizes.  Also recorded is the total compressed size for 14 files of
321 the Calgary Text Compression Corpus totalling 3,141,622 bytes.  This
322 column gives some feel for how compression varies with block size.
323 These figures tend to understate the advantage of larger block sizes for
324 larger files, since the Corpus is dominated by smaller files.
326            Compress   Decompress   Decompress   Corpus
327     Flag     usage      usage       -s usage     Size
329      -1      1200k       500k         350k      914704
330      -2      2000k       900k         600k      877703
331      -3      2800k      1300k         850k      860338
332      -4      3600k      1700k        1100k      846899
333      -5      4400k      2100k        1350k      845160
334      -6      5200k      2500k        1600k      838626
335      -7      6100k      2900k        1850k      834096
336      -8      6800k      3300k        2100k      828642
337      -9      7600k      3700k        2350k      828642
339 .SH RECOVERING DATA FROM DAMAGED FILES
340 .I bzip2
341 compresses files in blocks, usually 900kbytes long.  Each
342 block is handled independently.  If a media or transmission error causes
343 a multi-block .bz2
344 file to become damaged, it may be possible to
345 recover data from the undamaged blocks in the file.
347 The compressed representation of each block is delimited by a 48-bit
348 pattern, which makes it possible to find the block boundaries with
349 reasonable certainty.  Each block also carries its own 32-bit CRC, so
350 damaged blocks can be distinguished from undamaged ones.
352 .I bzip2recover
353 is a simple program whose purpose is to search for
354 blocks in .bz2 files, and write each block out into its own .bz2 
355 file.  You can then use
356 .I bzip2 
358 to test the
359 integrity of the resulting files, and decompress those which are
360 undamaged.
362 .I bzip2recover
363 takes a single argument, the name of the damaged file, 
364 and writes a number of files "rec00001file.bz2",
365 "rec00002file.bz2", etc, containing the  extracted  blocks.
366 The  output  filenames  are  designed  so  that the use of
367 wildcards in subsequent processing -- for example,  
368 "bzip2 -dc  rec*file.bz2 > recovered_data" -- processes the files in
369 the correct order.
371 .I bzip2recover
372 should be of most use dealing with large .bz2
373 files,  as  these will contain many blocks.  It is clearly
374 futile to use it on damaged single-block  files,  since  a
375 damaged  block  cannot  be recovered.  If you wish to minimise 
376 any potential data loss through media  or  transmission errors, 
377 you might consider compressing with a smaller
378 block size.
380 .SH PERFORMANCE NOTES
381 The sorting phase of compression gathers together similar strings in the
382 file.  Because of this, files containing very long runs of repeated
383 symbols, like "aabaabaabaab ..."  (repeated several hundred times) may
384 compress more slowly than normal.  Versions 0.9.5 and above fare much
385 better than previous versions in this respect.  The ratio between
386 worst-case and average-case compression time is in the region of 10:1.
387 For previous versions, this figure was more like 100:1.  You can use the
388 \-vvvv option to monitor progress in great detail, if you want.
390 Decompression speed is unaffected by these phenomena.
392 .I bzip2
393 usually allocates several megabytes of memory to operate
394 in, and then charges all over it in a fairly random fashion.  This means
395 that performance, both for compressing and decompressing, is largely
396 determined by the speed at which your machine can service cache misses.
397 Because of this, small changes to the code to reduce the miss rate have
398 been observed to give disproportionately large performance improvements.
399 I imagine 
400 .I bzip2
401 will perform best on machines with very large caches.
403 .SH CAVEATS
404 I/O error messages are not as helpful as they could be.
405 .I bzip2
406 tries hard to detect I/O errors and exit cleanly, but the details of
407 what the problem is sometimes seem rather misleading.
409 This manual page pertains to version 1.0.6 of
410 .I bzip2.  
411 Compressed data created by this version is entirely forwards and
412 backwards compatible with the previous public releases, versions
413 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1, 1.0.2 and above, but with the following
414 exception: 0.9.0 and above can correctly decompress multiple
415 concatenated compressed files.  0.1pl2 cannot do this; it will stop
416 after decompressing just the first file in the stream.
418 .I bzip2recover
419 versions prior to 1.0.2 used 32-bit integers to represent
420 bit positions in compressed files, so they could not handle compressed
421 files more than 512 megabytes long.  Versions 1.0.2 and above use
422 64-bit ints on some platforms which support them (GNU supported
423 targets, and Windows).  To establish whether or not bzip2recover was
424 built with such a limitation, run it without arguments.  In any event
425 you can build yourself an unlimited version if you can recompile it
426 with MaybeUInt64 set to be an unsigned 64-bit integer.
430 .SH AUTHOR
431 Julian Seward, jsewardbzip.org.
433 http://www.bzip.org
435 The ideas embodied in
436 .I bzip2
437 are due to (at least) the following
438 people: Michael Burrows and David Wheeler (for the block sorting
439 transformation), David Wheeler (again, for the Huffman coder), Peter
440 Fenwick (for the structured coding model in the original
441 .I bzip,
442 and many refinements), and Alistair Moffat, Radford Neal and Ian Witten
443 (for the arithmetic coder in the original
444 .I bzip).  
445 I am much
446 indebted for their help, support and advice.  See the manual in the
447 source distribution for pointers to sources of documentation.  Christian
448 von Roques encouraged me to look for faster sorting algorithms, so as to
449 speed up compression.  Bela Lubkin encouraged me to improve the
450 worst-case compression performance.  
451 Donna Robinson XMLised the documentation.
452 The bz* scripts are derived from those of GNU gzip.
453 Many people sent patches, helped
454 with portability problems, lent machines, gave advice and were generally
455 helpful.