linux 中 bzip2压缩与解压缩

发布时间 2024-01-08 12:40:44作者: 小鲨鱼2018

 

001、测试文件

[root@pc1 test]# ls
a.txt
[root@pc1 test]# ll -h                            ## 测试文件
total 113M
-rw-r--r--. 1 root root 113M Jan  9 12:03 a.txt

 

002、压缩文件(不保留源文件)

[root@pc1 test]# ls
a.txt
[root@pc1 test]# bzip2 a.txt             ## 压缩文件,不保留源文件
[root@pc1 test]# ll -h
total 5.2M
-rw-r--r--. 1 root root 5.2M Jan  9 12:03 a.txt.bz2

 

002、压缩文件(保留源文件)

[root@pc1 test]# ls
a.txt
[root@pc1 test]# bzip2 -k a.txt                ## 压缩文件,并保留源文件
[root@pc1 test]# ls
a.txt  a.txt.bz2
[root@pc1 test]# ll -h
total 118M
-rw-r--r--. 1 root root 113M Jan  9 12:03 a.txt
-rw-r--r--. 1 root root 5.2M Jan  9 12:03 a.txt.bz2

 。

 

003、解压bz2文件(不保留源文件)

[root@pc1 test]# ls
a.txt.bz2
[root@pc1 test]# bunzip2 a.txt.bz2       ## 解压bz2文件(不保留源文件)
[root@pc1 test]# ls
a.txt
[root@pc1 test]# ll -h
total 113M
-rw-r--r--. 1 root root 113M Jan  9 12:03 a.txt

 

 

004、解压bz2文件(保留源文件)

[root@pc1 test]# ls
a.txt.bz2
[root@pc1 test]# bunzip2 -k a.txt.bz2          ## 解压bz2文件,并保留源文件
[root@pc1 test]# ls
a.txt  a.txt.bz2
[root@pc1 test]# ll -h
total 118M
-rw-r--r--. 1 root root 113M Jan  9 12:03 a.txt
-rw-r--r--. 1 root root 5.2M Jan  9 12:03 a.txt.bz2

 。