Linux压缩及解压缩命令

常用压缩格式: .zip .gz .bz2 .tar.gz .tar.bz2

.zip格式压缩

#压缩文件
命令: zip 压缩文件名 源文件
#压缩当前目录下所有文件为test.zip

   root@virtual-machine:$ zip test.zip ./*
   adding: const.properties (deflated 44%)
   adding: emq.conf (deflated 71%)
   adding: getheadimg.jpeg (deflated 1%)

#压缩目录
命令: zip -r 压缩文件名 源目录
#压缩指定目录为test02.zip

   root@virtual-machine:$ zip -r test02.zip /home/chroot/tartest/
   adding: home/chroot/tartest/ (stored 0%)
   adding: home/chroot/tartest/test.zip (stored 0%)
   adding: home/chroot/tartest/getheadimg.jpeg (deflated 1%)
   adding: home/chroot/tartest/const.properties (deflated 44%)
   adding: home/chroot/tartest/emq.conf (deflated 71%)

.zip格式解压缩

命令:unzip 压缩文件
#解压缩.zip文件

   root@virtual-machine:$ unzip test02.zip 
   Archive:  test02.zip
   creating: home/chroot/tartest/
   inflating: home/chroot/tartest/getheadimg.jpeg  
   inflating: home/chroot/tartest/const.properties  
   inflating: home/chroot/tartest/emq.conf  

.gz格式压缩

gzip 源文件
#压缩为.gz格式的压缩文件,源文件会消失
命令: gzip 源文件 > 压缩文件

root@virtual-machine:$ gzip emq.conf > emq.gz

#压缩为.gz格式,源文件保留
命令: gzip -c 源文件 > 压缩文件

root@virtual-machine:$ gzip -c const.properties > const.gz

.gz格式解压缩

命令: gzip -d 压缩文件
#解压缩文件

 root@virtual-machine:$ gzip -d emq.conf.gz 

命令: gunzip 压缩文件
#解压缩文件

root@virtual-machine:$ gunzip const.gz 

.bz2格式压缩

命令: bzip2 源文件
#压缩为.bz2格式,不保留源文件

root@virtual-machine:$ bzip2 const.properties

#自动生成const.properties.bz2

命令: bzip2 -k 源文件
#压缩之后保留源文件
注意: bzip2命令不能压缩目录

root@virtual-machine:$ bzip2 -k const

#自动生成const.bz2

.bz2格式解压缩

命令: bzip2 -d 压缩文件
#解压缩,-k保留压缩文件

root@virtual-machine:$ bzip2 -d const.bz2 

命令: bunzip2 压缩文件
#解压缩,-k 保留压缩文件

 root@virtual-machine:$ bunzip2 -k emq.conf.bz2 

tar格式压缩命令

命令: tar -cvf 打包文件名 源文件
选项:
-c: 打包
-v: 显示过程
-f: 指定打包后的文件名
例如:

root@virtual-machine:$ tar -cvf file.tar ./

tar格式解压缩命令

命令: tar -xvf 打包文件名
选项:
-x: 解打包
例如:

root@virtual-machine:$ tar -xvf file.tar

.tar.gz压缩格式

其实.tar.gz格式是先打包为.tar格式,再压缩为.gz格式
命令: tar -zcvf 压缩包名.tar.gz 源文件
选项:
-z: 压缩为.tar.gz格式

root@virtual-machine:$ tar -zcvf file.tar.gz ./

.tar.gz解压缩格式

命令: tar -zxvf 压缩包名.tar.gz
选项:
-x: 解压缩.tar.gz格式

root@virtual-machine:$ tar -zxvf file.tar.gz

.tar.bz2压缩格式

命令: tar -jcvf 压缩包名.tar.bz2 源文件
选项:
-z: 压缩为.tar.bz2格式

root@virtual-machine:$ tar -jcvf file.tar.bz2 ./home

.tar.bz2解压缩格式

命令: tar -jxvf 压缩包名.tar.bz2
选面:
-x: 解压缩.tar.bz2格式

root@virtual-machine:$ tar -jxvf file.tar.bz2 

解压缩指定位置命令

命令: tar -jzxf 压缩文件.tar.gz -C 目录
压缩多个文件及指定压缩文件保存位置:

root@virtual-machine:$ tar -jxvf file.tar.bz2 -C /tmp/

查看压缩包内容不解压命令

命令: tar -ztvf 压缩文件.tar.gz

root@virtual-machine:$ tar -ztvf file.tar.gz
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值