Linux之bzip2压缩和解压缩

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

选项

命令英文含义
jbzip2使用bzip2压缩和解压缩
ccreate生成档案文件,创建打包文件
xextract(提取)解包
vverbosely显示打包或解包过程
ffile指定打包文件名(.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]# 
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值