Use of Linux bzip2 command

Use of Linux bzip2 command

1. Command Introduction

bzip2 is used to compress and decompress files. It is a command often used in Linux systems to compress and decompress files. It uses the Burrow-Wheeler block sorting text compression algorithm and Huffman coding to compress files into bzip2 files with the suffix .bz2. The compression ratio is generally much better than that of LZ77/LZ78 based compression software, and its performance is close to that of PPM family statistical compression software.

bzip2 can not only be used to compress large, seldom-used files to save disk space, but can also be used with the tar command to package and compress files. Reducing file size has two obvious benefits. One is that it can reduce storage space. The other is that when transferring files over the network, it can reduce the transmission time.

2. Command format

bzip2 [OPTIONS] [FILES...]

The bzip2 command line arguments are intentionally designed to be close to GNU gzip's, but not identical. bzip2 reads options and file names from the command line. Each file is replaced by a compressed file named "originalfilename.bz2". Each compressed file has the same modification time, permissions, and, if possible, owner as the original file, so these characteristics will be correctly restored when decompressing it.

By default bzip2 does not overwrite existing files. If you want to overwrite an existing file, specify the -f option.

3. Option Description

-c, --stdout
  Compress or decompress data to standard output -d, --decompress
  Force decompression. bzip2, bunzip2 and bzcat are actually the same program, and the operation they perform is determined by the program name. Specifying this option will override this mechanism and force bzip2 to decompress -z, --compress
	-d option supplement: force compression operation regardless of which program is executed -t, --test
  Checks the integrity of the specified file without decompressing it. In fact, the data will be experimentally decompressed without outputting the result -f, -force
  Force overwriting of output file. Normally bzip2 will not overwrite existing files. This option also forces bzip2 to break hard links in files, which bzip2 does not do by default.
-k, --keep
  Keep input files when compressing or decompressing (do not delete them)
-s, --small
  Reduce memory usage when compressing, decompressing, and checking. A modified algorithm is used for compression and testing, requiring only 2.5 bytes per data block. This means that any file can be decompressed in 2300K of memory, although at only half the normal speed. When compressing, -s will select a block length of 200K, and the memory usage will also be limited to around 200K, at the expense of a lower compression ratio. In summary, if the machine has low memory (8MB or less), use the -s option for all operations. -q, --quiet
  Suppress unimportant warning messages. Information about I/O errors and other serious events will not be suppressed -v, --verbose
  Verbose mode - displays the compression ratio of each processed file. More -v options on the command line will increase the verbosity level, causing bzip2 to display a lot of information mainly for diagnostic purposes. -L, --license, -V, --version
	Display software version, license terms and distribution conditions -1 (or --fast) to -9 (or --best)
  When compressing, set the block length to 100 k, 200 k, ... 900 k. Has no effect on decompression --
  Treat all subsequent command-line arguments as file names, even if they begin with a minus sign -. This option can be used to process file names starting with a minus sign -, for example: bzip2 -- -myfilename
--repetitive-fast, --repetitive-best
  These options are redundant in versions 0.9.5 and above. In earlier versions, these two options provided some coarse-grained control over the behavior of the sorting algorithm, which was useful in some situations. Versions 0.9.5 and above use an improved algorithm regardless of these options.

4. Common Examples

(1) The original file is not compressed.

bzip2 /etc/passwd

After compression, /etc/passwd will become /etc/passwd.bz2.

(2) Keep the original file compression.

bzip2 -k /etc/passwd
# or bzip2 -c /etc/passwd > /etc/passwd.bz2

(3) Display the instruction execution process during compression.

bzip2 -v /etc/passwd
/etc/passwd: 2.256:1, 3.546 bits/byte, 55.67% saved, 1552 in, 688 out.

(4) Decompress the .bz2 file without retaining the original file.

bzip2 -d /etc/passwd.bz2

(5) Unzip the .bz2 file and keep the original file.

bzip2 -dk /etc/passwd.bz2
# or bzip2 -dc /etc/passwd.bz2 > /etc/passwd

(6) Test the integrity of the .bz2 compressed file without actually decompressing it.

bzip2 -tv /etc/passwd.bz2
/etc/passwd.bz2: ok

The above is the detailed content of using Linux bzip2 command. For more information about Linux bzip2 command, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Implementing Python to monitor USB device signals under Linux
  • Detailed explanation of Linux USB host driver writing
  • arm linux uses alsa driver and uses usb audio device
  • How to use USB mobile storage in Linux
  • Using USB storage in Linux environment
  • In-depth analysis of Linux NFS mechanism through cases
  • Working principle and example analysis of Linux NFS mechanism
  • IntelliJ IDEA remote debugging Linux Java program, find the problem do not just look at the log (recommended)
  • How to use libudev in Linux to get USB device VID and PID

<<:  MySQL loop inserts tens of millions of data

>>:  Vue uses plug-ins to cut pictures in proportion

Recommend

JavaScript CollectGarbage Function Example

First, let's look at an example of memory rel...

The easiest way to reset mysql root password

My mysql version is MYSQL V5.7.9, please use the ...

How to implement a multi-terminal bridging platform based on websocket in JS

Table of contents 1. What to debug 2. Features of...

Docker realizes the connection with the same IP network segment

Recently, I solved the problem of Docker and the ...

Vue3.0 handwriting magnifying glass effect

The effect to be achieved is: fixed zoom in twice...

How to position the header at the top using CSS sticky layout

Application scenarios: One of the new requirement...

Detailed explanation of Vue's hash jump principle

Table of contents The difference between hash and...

Optimized implementation of count() for large MySQL tables

The following is my judgment based on the data st...

How to import SQL files in Navicat Premium

I started working on my final project today, but ...

Website front-end performance optimization: JavaScript and CSS

I have read an article written by the Yahoo team ...

Docker cleaning killer/Docker overlay file takes up too much disk space

[Looking at all the migration files on the Intern...

Detailed explanation of mysql backup and recovery

Preface: The previous articles introduced the usa...

Use Smart CSS to apply styles based on the user's scroll position

By adding the current scroll offset to the attrib...