Linux之bzip2压缩和解压缩
bzip2是Linux的另一种压缩格式,用于操作".bz2"格式的的文件,“.bz2"格式的算法更加先进,压缩比更好。”.gz"格式压缩比略差,但是压缩时间会更快。
Linux中,bzip压缩文件格式,xxx.tar.bz2。
Linux中,bzip,使用tar加选项-j来调用。
命令格式
tar -jcvf 打包压缩文件名.tar.bz2 被压缩的文件/目录 --压缩文件
tar -jxvf 打包文件.tar.bz2 --解压缩文件
tar -jxvf 打包文件.tar.bz2 -C 目录路径 --解压缩到指定路径
注意:如果Linux报错
tar (child): bzip2:无法 exec: 没有那个文件或目录
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
使用下发语句安装bzip2。
yum install -y bzip2
选项
命令 | 英文 | 含义 |
---|---|---|
j | bzip2 | 使用bzip2压缩和解压缩 |
c | create | 生成档案文件,创建打包文件 |
x | extract(提取) | 解包 |
v | verbosely | 显示打包或解包过程 |
f | file | 指定打包文件名(.tar)或压缩包文件名 |
C(大写) | directory(目录) | 默认保存到当前目录,-C更改提取目录,注意:指定的提取目录必须提前存在。 |
例子
[root@localhost work]# tar -jcvf 010203.tar.bz2 01.txt 02.txt 03.txt workspace/ --使用bzip2压缩文件和目录
01.txt
02.txt
03.txt
workspace/
[root@localhost work]# ll
总用量 8
-rw-r--r--. 1 root root 224 6月 17 18:50 010203.tar.bz2
-rw-r--r--. 1 root root 0 6月 14 00:25 01.txt
-rw-r--r--. 1 root root 35 6月 14 00:25 02.txt
-rw-r--r--. 1 root root 0 6月 14 00:26 03.txt
drwxr-xr-x. 2 root root 6 6月 17 18:42 workspace
[root@localhost work]# tar -jxvf 010203.tar.bz2 -C workspace/ --解压.tar.bz2到指定目录
01.txt
02.txt
03.txt
workspace/
[root@localhost work]# tree workspace/
workspace/
├── 01.txt
├── 02.txt
├── 03.txt
└── workspace
1 directory, 3 files
[root@localhost work]#