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

In-depth explanation of MySQL learning engine, explain and permissions

engine Introduction Innodb engine The Innodb engi...

js to realize the mouse following game

This article shares the specific code of js to im...

A brief analysis of the count tracking of a request in nginx

First, let me explain the application method. The...

Detailed explanation of MySQL database index

Table of contents 1. Introduction to MySQL Index ...

React error boundary component processing

This is the content of React 16. It is not the la...

Serial and parallel operations in JavaScript

Table of contents 1. Introduction 2. es5 method 3...

Detailed explanation of using MySQL where

Table of contents 1. Introduction 2. Main text 2....

JavaScript exquisite snake implementation process

Table of contents 1. Create HTML structure 2. Cre...

Web Design Tutorial (8): Web Page Hierarchy and Space Design

<br />Previous article: Web Design Tutorial ...

Vue.js performance optimization N tips (worth collecting)

Table of contents Functionalcomponents Childcompo...

Mobile web screen adaptation (rem)

Preface I recently sorted out my previous notes o...

A brief introduction to mysql mycat middleware

1. What is mycat A completely open source large d...