linux bunzip2 命令介绍
Linux 中的 bunzip2 命令用于解压缩使用 bzip2 压缩算法压缩的文件
bunzip2命令 解压缩由bzip2指令创建的”.bz2"压缩包。对文件进行压缩与解压缩。此命令类似于“gzip/gunzip”命令,只能对文件进行压缩。对于目录只能压缩目录下的所有文件,压缩完成后,在目录下生成以“.bz2”为后缀的压缩包。bunzip2其实是bzip2的符号链接,即软链接,因此压缩解压都可以通过bzip2实现
一:安装部署
root@meng:/data# which bunzip2
root@meng:/data# bunzip2
Command 'bunzip2' not found, but can be installed with:
apt install bzip2
root@meng:/data# apt install bzip2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
bzip2-doc
The following NEW packages will be installed:
bzip2
0 upgraded, 1 newly installed, 0 to remove and 216 not upgraded.
Need to get 34.8 kB of archives.
After this operation, 117 kB of additional disk space will be used.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/main amd64 bzip2 amd64 1.0.8-5build1 [34.8 kB]
Fetched 34.8 kB in 1s (48.5 kB/s)
Selecting previously unselected package bzip2.
(Reading database ... 75058 files and directories currently installed.)
Preparing to unpack .../bzip2_1.0.8-5build1_amd64.deb ...
Unpacking bzip2 (1.0.8-5build1) ...
Setting up bzip2 (1.0.8-5build1) ...
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
二:命令语法
bunzip2 [OPTION]... [FILE]...常用选项包括:
-k: 保留原始文件(不删除压缩后的文件)-f: 强制解压缩(即使目标文件已存在)-v: 显示详细的解压缩过程信息root@meng:/data# bunzip2
bunzip2: I won't read compressed data from a terminal.
bunzip2: For help, type: `bunzip2 --help'.
root@meng:/data# bunzip2 --help
bzip2, a block-sorting file compressor. Version 1.0.8, 13-Jul-2019.
usage: bunzip2 [flags and input files in any order]
-h --help print this message
-d --decompress force decompression
-z --compress force compression
-k --keep keep (don't delete) input files
-f --force overwrite existing output files
-t --test test compressed file integrity
-c --stdout output to standard out
-q --quiet suppress noncritical error messages
-v --verbose be verbose (a 2nd -v gives more)
-L --license display software version & license
-V --version display software version & license
-s --small use less memory (at most 2500k)
-1 .. -9 set block size to 100k .. 900k
--fast alias for -1
--best alias for -9
If invoked as `bzip2', default action is to compress.
as `bunzip2', default action is to decompress.
as `bzcat', default action is to decompress to stdout.
If no file names are given, bzip2 compresses or decompresses
from standard input to standard output. You can combine
short flags, so `-v -4' means the same as -v4 or -4v, &c.
三:案例
root@meng:~# ls
0c86af62-fd21-4a77-be08-a53c49bd8c8f.zip meng.txt snap
root@meng:~# bunzip2 meng.txt^C
root@meng:~# bzip2 -9vk meng.txt 0c86af62-fd21-4a77-be08-a53c49bd8c8f.zip
meng.txt: 1.408:1, 5.682 bits/byte, 28.98% saved, 245 in, 174 out.
0c86af62-fd21-4a77-be08-a53c49bd8c8f.zip: 1.019:1, 7.853 bits/byte, 1.84% saved, 20593006 in, 20214290 out.
root@meng:~# ls -h
0c86af62-fd21-4a77-be08-a53c49bd8c8f.zip 0c86af62-fd21-4a77-be08-a53c49bd8c8f.zip.bz2 meng.txt meng.txt.bz2 snap
root@meng:~# ll
total 39988
drwx------ 8 root root 4096 Aug 16 19:32 ./
drwxr-xr-x 20 root root 4096 Aug 14 09:54 ../
-rw------- 1 root root 50831 Aug 15 09:15 .bash_history
-rw-r--r-- 1 root root 3106 Oct 15 2021 .bashrc
drwx------ 2 root root 4096 Jun 25 2023 .cache/
drwx------ 4 root root 4096 Jun 19 17:20 .config/
drwx------ 3 root root 4096 Jun 11 18:18 .docker/
-rw------- 1 root root 20 Jun 7 15:05 .lesshst
-rw-r--r-- 1 root root 161 Jul 9 2019 .profile
drwx------ 2 root root 4096 Apr 19 16:33 .ssh/
drwxr-xr-x 2 root root 4096 Jun 7 15:02 .vim/
-rw------- 1 root root 22185 Aug 13 09:21 .viminfo
-rw-r--r-- 1 root root 165 Jun 7 11:17 .wget-hsts
-rw-r--r-- 1 root root 20593006 Aug 13 09:32 0c86af62-fd21-4a77-be08-a53c49bd8c8f.zip
-rw-r--r-- 1 root root 20214290 Aug 13 09:32 0c86af62-fd21-4a77-be08-a53c49bd8c8f.zip.bz2
-rw-r--r-- 1 root root 245 Aug 13 09:21 meng.txt
-rw-r--r-- 1 root root 174 Aug 13 09:21 meng.txt.bz2
drwx------ 3 root root 4096 Apr 19 14:21 snap/
root@meng:~# bunzip2 meng.txt.bz2
bunzip2: Output file meng.txt already exists.
root@meng:~# bunzip2 -k meng.txt.bz2
bunzip2: Output file meng.txt already exists.
root@meng:~# bunzip2 --keep meng.txt.bz2
bunzip2: Output file meng.txt already exists.
root@meng:~# bunzip2 -f meng.txt.bz2
root@meng:~# ll -h
total 40M
drwx------ 8 root root 4.0K Aug 16 19:34 ./
drwxr-xr-x 20 root root 4.0K Aug 14 09:54 ../
-rw------- 1 root root 50K Aug 15 09:15 .bash_history
-rw-r--r-- 1 root root 3.1K Oct 15 2021 .bashrc
drwx------ 2 root root 4.0K Jun 25 2023 .cache/
drwx------ 4 root root 4.0K Jun 19 17:20 .config/
drwx------ 3 root root 4.0K Jun 11 18:18 .docker/
-rw------- 1 root root 20 Jun 7 15:05 .lesshst
-rw-r--r-- 1 root root 161 Jul 9 2019 .profile
drwx------ 2 root root 4.0K Apr 19 16:33 .ssh/
drwxr-xr-x 2 root root 4.0K Jun 7 15:02 .vim/
-rw------- 1 root root 22K Aug 13 09:21 .viminfo
-rw-r--r-- 1 root root 165 Jun 7 11:17 .wget-hsts
-rw-r--r-- 1 root root 20M Aug 13 09:32 0c86af62-fd21-4a77-be08-a53c49bd8c8f.zip
-rw-r--r-- 1 root root 20M Aug 13 09:32 0c86af62-fd21-4a77-be08-a53c49bd8c8f.zip.bz2
-rw-r--r-- 1 root root 245 Aug 13 09:21 meng.txt
drwx------ 3 root root 4.0K Apr 19 14:21 snap/