liunx 常用压缩与解压缩

1、zip

压缩文件

zip 压缩文件名   压缩文件  (zip xxx.zip  file)

压缩目录

zip -r 压缩文件名  压缩目录   (zip -r xxx.zip  /dir) 

解压缩

unzip xxx.zip(解压到当前目录)

unzip -d  /dir  xxx.zip(解压到指定目录 )     

2、gzip(.gz格式,不能打包

压缩

gzip file    (打包file文件自动生成 file.gz ,原file将被删除)

gzip -c file >file.gz(打包file文件生成 file.gz原file将保留)

gzip -r dir (将目录下的所有文件全部压缩成.gz)

解压缩

gzip -d file.gz

gzip -dr dri(将目录下的所有已压缩的文件解缩)

3、bzip2(.bz2格式 不能压缩目录

压缩

bzip2  -kv file (将文件压缩成file.bz2文件,参数k保留原文件,v显示压缩信息)

解压缩

bzip2 -dk file.bz2  (将文件file.bz2解压,参数k保留原压缩文件)

4、tar(只打包不压缩)

压缩

tar [选项] [-f 压缩包名] 源文件或目录
-c: 打包
-f: 指定压缩包的文件名。压缩包的扩展名是用来给管理员识别格式的,所以一定要正确指定扩展名
-v: 显示打包文件过程

如:#tar -cvf file.tar /etc

解压缩

tar [选项] 压缩包
选项:
-x: 解打包
-f: 指定压缩包的文件名
-v: 显示解打包文件过程
-t: 测试,就是不解打包,只是查看包中有哪些文件 

-C(大) 目录:指定解打包位置

如:
# tar -xvf file.tar -C a/b/ 

5、“.tar.gz”和“.tar.bz2”格式
使用tar命令直接打包压缩。命令格式如下:
[root@localhost ~]# tar [选项] 压缩包源文件或目录
选项:
-z: 压缩和解压缩“.tar.gz”格式
-j: 压缩和解压缩“.tar.bz2”格式
例如:.tar.gz格式
[root@localhost ~]# tar -zcvf tmp.tar.gz /tmp/
#把/tmp/目录直接打包压缩为“.tar.gz”格式
[root@localhost ~]# tar -zxvf tmp.tar.gz
#解压缩与解打包“.tar.gz”格式
例如:.tar.bz2格式
[root@localhost ~]# tar -jcvf tmp.tar.bz2 /tmp/
#打包压缩为“.tar.bz2”格式,注意压缩包文件名
[root@localhost ~]# tar -jxvf tmp.tar.bz2
#解压缩与解打包“.tar.bz2”格式
再举几个例子:
[root@localhost ~]# mkdir test
[root@localhost ~]# touch test/abc
[root@localhost ~]# touch test/bcd
[root@localhost ~]# touch test/cde
#建立测试目录和测试文件
[root@localhost ~]# tar -zcvf test.tar.gz test/
#压缩
[root@localhost ~]# tar -ztvf test.tar.gz
#只查看,不解压
[root@localhost ~]# tar -zxvf test.tar.gz -C /tmp
#解压缩到指定位置
[root@localhost ~]# tar -zxvf test.tar.gz -C /tmp test/cde
#只解压压缩包中的特定文件,到指定位置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值