bzip2.1 16 KB

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