Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the bzip2 command in Linux

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to use bzip2 commands in Linux", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use bzip2 commands in Linux" this article.

The bzip2 command is used to create and manage (including unzipping) compressed packages in ".bz2" format

Bzip2 compresses the file into bz2 format

It is added that bzip2 uses Burrows-Wheeler block sorting text compression algorithm and Huffman encoding to compress files. The compression ratio is generally much better than that of LZ77/LZ78-based compression software, and its performance is close to that of PPM statistical compression software.

The command-line arguments are intentionally designed to be very close to GNU gzip, but not exactly the same.

Bzip2 reads the file name and parameters from the command line. Each file is replaced by a compressed file named "original file name .bz2". Each compressed file has the same modification time, permissions, and, if possible, the same owner, so these features will be restored correctly when unzipped. In some file systems, there is no concept of permissions, ownership, or time, or there are strict restrictions on the length of file names, such as MSDOS. In this case, bzip2 has no mechanism to maintain the original file name, ownership, permissions, and time. In this sense, bzip2's handling of file names is naive.

Bzip2 and bunzip2 do not overwrite existing files by default. If you want to overwrite an existing file, specify the-f option.

If no filename is specified, bzip2 compresses the data from standard input and writes it to standard output. In this case, bzip2 refuses to write the compression result to the terminal because it is completely incomprehensible and meaningless.

Bunzip2 (and bzip2-d) decompresses all specified files. Files that are not generated by bzip2 will be ignored with a warning message. Bzip2 determines the decompressed file name from the compressed file name in the following ways:

Filename.bz2 decompressed into filename filename.bz, decompressed into filename.tar filename.tbz, decompressed into filename.tar anyothername, decompressed into anyothername.out if the suffix of the file name is not one of the following: .bz2, .bz, .tbz2 or .tbz, .bzip2 will complain that the original file name cannot be determined, and use the original file name plus .out as the unzipped file name.

During compression, if you do not provide a file name, bzip2 will read the data from the standard input and write the compression result to the standard output.

Bzip2 uses a 32-bit CRC check code to verify that the decompressed file is the same as the original file. This can be used to detect whether the compressed file is corrupted and to prevent unknown defects in bzip2 (which, with luck, is highly unlikely). The chance of data corruption going undetected is very small, about 1/4000000000 for each file being processed. The check is done during unzipping, so it can only indicate that something is wrong. It can help recover the original uncompressed data. You can use bzip2recover to try to recover data from corrupted files.

Return value: 0 for normal exit, 1 for environmental problems (file not found, illegal options, Icano error, etc.), 2 indicates that the compressed file is corrupted, and 3 is returned for internal consistency errors (such as defects) that lead to bzip2 emergency exit.

Syntax bzip2 [- cdfkqstvzVL123456789] [filenames...] option-c-- stdout # compresses or decompresses data to standard output. -d-- decompress # forces decompression. Bzip2, bunzip2, and bzcat are actually the same program, and what to do will be determined by the program name. When this option is specified, this mechanism is ignored and bzip2 is forced to decompress. -z-- supplement to the compress #-d option: forces compression operations, regardless of which program is being executed. -t-- test # checks the integrity of the specified file, but does not extract it. The data will actually be experimentally decompressed without outputting the results. -f-- force # forces the output file to be overwritten Usually bzip2 does not overwrite files that already exist. This option also forces bzip2 to break the hard connection of the file, which bzip2 does not do by default. -k-- keep # retains input files when compressed or unzipped (these files are not deleted) -s-- small # reduces memory usage when compressing, decompressing, and checking. Using a modified algorithm for compression and testing, each data block requires only 2.5 bytes. This means that any file can be unzipped in 2300k # memory, albeit at half the usual speed. # when compressing,-s will select a block length of 200k, and the amount of memory will be limited to about 200k, at the cost of reducing the compression ratio. In short, if the machine has less memory (8 megabytes or less), # can use the-s option for all operations. See memory management below. -Q-- quiet # suppresses unimportant warnings. Messages related to Icano errors and other serious events will not be suppressed. -v-- verbose # verbose mode-shows the compression ratio of each file being processed. More-v options on the command line will increase the level of detail so that bzip2 displays a lot of information that is used primarily for diagnostic purposes. -L-- license-V-- version # shows the software version, license terms and conditions. -1 to-9 # sets the block length to 100k and 200k during compression. 900 k . It has no effect on decompression. See memory management below. -- # treat all subsequent command-line variables as file names, even if they start with a minus sign "-". You can use this option to handle file names that begin with the minus sign "-", for example: bzip2-myfilename. -- repetitive-fast-- repetitive-best # these options are redundant in 0.9.5 and above. In earlier versions, these two options provided some rough control over the behavior of the sorting algorithm, which was useful in some cases. Version 0.9.5 and above uses improved algorithms independent of these options. Parameter file: specifies the file to be compressed.

The specified file filename is compressed by the instance:

Bzip2 filename or bzip2-z filename here, compression will not output, the original file filename will be deleted and replaced with filename.bz2. If there is a filename.bz2 in the past, it will not replace and prompt an error (specify the-f option if you want to replace, such as bzip2-f filename; if filename is a directory, then remind the error not to do anything; if the filename is already overloaded, there is a bz2 suffix to remind you, no more compression, no bz2 suffix will be compressed again.

Extract the specified file filename.bz2:

Bzip2-d filename.bz2 or bunzip2 filename.bz2 here, there is no standard output when decompressing, so the original file filename.bz2 will be replaced with filename. If there is a previous filename, it will not be replaced and an error will be prompted (if you want to replace, specify the-f option, such as bzip2-df filename.bz2.

When compressing and decompressing, the result is also output:

After entering $bzip2-v filename, the output is as follows:

Filename: 0.119 saved 1, 67.200 bits/byte,-740.005% saved, 5 in, 42 out. Here, add-v option will output, only use compression example, decompression when the same bzip2-dv filename.bz2 is no longer an example.

Simulated decompression does not actually decompress:

After entering bzip2-tv filename.bz2, the output is as follows:

Filename.bz2: ok here,-t specifies the simulation decompression, which does not actually generate results, that is, similar check files, of course, even if there is filename under the directory, there will not be any error output, because it will not really decompress the files at all. In order to output on the screen, the-v option is added here, and if it is true to extract bzip2-dv filename.bz2, the output is to replace "ok" with "done".

When compressing and decompressing, in addition to generating the result file, save the original file:

Bzip2-k filename here, add-k to save the original file, otherwise the original file will be replaced by the result file. Only use the compression example, decompression when the same $bzip2-dk filename.bz2 no longer example.

Extract to standard output:

After entering bzip2-dc filename.bz2, the output is as follows:

Hahahhaahahha here, use-c to specify to standard output, output is the contents of the file filename, filename.bz2 will not be deleted.

Compress to standard output:

Bzip2-c filename bzip2: I won't write compressed data to a terminal. Bzip2: For help, type: `bzip2-- help'. Here, use-c to specify that compression to standard output does not delete the original file, except that the compressed file cannot be output to standard output.

When using bzip2, treat all the following as files (even if the file name starts with'-'):

Bzip2-myfilename here is mainly to prevent ambiguity in the file name that is thought to be an option.

The above is all the contents of the article "how to use bzip2 commands in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report