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

Vue implements a scroll bar style

At first, I wanted to modify the browser scroll b...

Detailed tutorial on installing Python 3.6.6 from scratch on CentOS 7.5

ps: The environment is as the title Install possi...

Detailed explanation of the role and principle of key in Vue

Table of contents 1. Let’s start with the conclus...

Understanding of CSS selector weight (personal test)

Copy code The code is as follows: <style type=...

Analysis of the use and principle of Docker Swarm cluster management

Swarm Cluster Management Introduction Docker Swar...

Does MySql need to commit?

Whether MySQL needs to commit when performing ope...

TortoiseSvn Little Turtle Installation Latest Detailed Graphics Tutorial

There were always problems when installing tortoi...

HTTP Status Codes

This status code provides information about the s...

Summary of Mysql-connector-java driver version issues

Mysql-connector-java driver version problem Since...

Detailed explanation of Zabbix installation and deployment practices

Preface Zabbix is ​​one of the most mainstream op...

Detailed explanation of how to use the vue3 Teleport instant movement function

The use of vue3 Teleport instant movement functio...

Summary of MySQL commonly used type conversion functions (recommended)

1. Concat function. Commonly used connection stri...

Json advantages and disadvantages and usage introduction

Table of contents 1. What is JSON 1.1 Array liter...

How to generate a unique server-id in MySQL

Preface We all know that MySQL uses server-id to ...