linux bz2 xz gz,压缩介绍、bz2、gz、xz压缩工具

压缩打包介绍

常见的压缩文件

Windows  .rar .zip .7z

Linux gz、zip、bz2、xz、tar.gz、tar.bz2、tar.xz

压缩对于磁盘节省空间

压缩对于传输传输时间短,节省带宽资源

gzip压缩工具

gzip 1.txt

[root@lsx1 ~]# ls

anaconda-ks.cfg  lsx.sh

[root@lsx1 ~]# gzip lsx.sh //压缩之后源文件消失

[root@lsx1 ~]# ls //压缩之后源文件消失

anaconda-ks.cfg  lsx.sh.gz

gzip -d 1.txt.gz / gunzip 1.txt.gz

[root@lsx1 ~]# gzip -d lsx.sh.gz  //解压缩

[root@lsx1 ~]# ls  //解压缩之后压缩包丢失

anaconda-ks.cfg  lsx.sh

gzip -# 1.txt  //#范围2021年05月14日,默认6

[root@lsx1 ~]# ll -h

-rw-r--r--  1 root root 169K 11月4 08:33 lsx.txt

[root@lsx1 ~]# gzip lsx.txt  //默认6

[root@lsx1 ~]# ll -h

-rw-r--r--  1 root root 46K 11月4 08:33 lsx.txt.gz

[root@lsx1 ~]# gzip -1 lsx.txt  //-1 //数值越大越严谨

[root@lsx1 ~]# ll -h

-rw-r--r--  1 root root 54K 11月4 08:33 lsx.txt.gz

不能压缩目录

[root@lsx1 ~]# gzip lsx  //不能压缩目录

gzip: lsx is a directory -- ignored

zcat 1.txt.gz

[root@lsx1 ~]# zcat lsx.txt.gz  //查看文件内容

gzip -c 1.txt > /root/1.txt.gz

[root@lsx1 ~]# gzip -c lsx.txt >./lsx.txt.gz  //-c 压缩但是源文件不消失,需指定压缩之后文件名

unzip -c /root/1.txt.gz > /tmp/1.txt.new

[root@lsx1 ~]# gzip -dc ./lsx.txt.gz > /tmp/lsx.txt  //解压缩。源文件不丢,解压之后文件需指定

[root@lsx1 ~]# ll /tmp/ -h

-rw-r--r-- 1 root root 169K 11月4 08:49 lsx.txt

bzip2压缩工具

bzip2 1.txt  / bzip2 -z 1.txt

[root@lsx1 ~]# bzip2 lsx.txt  //压缩成bz2文件,源文件消失

[root@lsx1 ~]# ll -h

-rw-r--r--  1 root root 43K 11月4 08:43 lsx.txt.bz2

-rw-r--r--  1 root root 46K 11月4 08:44 lsx.txt.gz

bzip2 -d 1.txt.bz2 / bunzip2 1.txt.bz2

[root@lsx1 ~]# bzip2 -d lsx.txt.bz2  //解压缩压缩包消失

[root@lsx1 ~]# ls

anaconda-ks.cfg  lsx  lsx.txt  lsx.txt.gz

bzip -# 1.txt  //#范围2021年05月14日,默认9  bzip压缩比gz严谨

[root@lsx1 ~]# bzip2 -1 lsx.txt

[root@lsx1 ~]# ll

-rw-r--r--  1 root root 45588 11月4 08:43 lsx.txt.bz2

-rw-r--r--  1 root root 46625 11月4 08:44 lsx.txt.gz

[root@lsx1 ~]# bzip2 -9 lsx.txt

[root@lsx1 ~]# ll -h

-rw-r--r--  1 root root 43K 11月4 08:43 lsx.txt.bz2

-rw-r--r--  1 root root 46K 11月4 08:44 lsx.txt.gz

不能压缩目录

[root@lsx1 ~]# bzip2 lsx

bzip2: Input file lsx is a directory.

bzcat 1.txt.bz2

[root@lsx1 ~]# bzcat lsx.txt.bz2 //查看文件内容

bzip2 -c 1.txt > /root/1.txt.bz

[root@lsx1 ~]# bzip2 -c ./lsx.txt>./lsx.txt.bz2  //压缩。源文件不消失,指定压缩后文件

[root@lsx1 ~]# ls

lsx.txt  lsx.txt.bz2  lsx.txt.gz

bzip2 -c -d /root/1.txt.bz2 > /tmp/1.txt.new2

[root@lsx1 ~]# bzip2 -dc lsx.txt.bz2 > /tmp/lsx.bzip2  //解压压缩包不消失,需指定压缩后文件

[root@lsx1 ~]# ls /tmp/

lsx.bzip2

xz压缩工具

xz 1.txt  / xz -z 1.txt

[root@lsx1 ~]# xz lsx.txt //压缩文件

[root@lsx1 ~]# ll -h

-rw-r--r--  1 root root 43K 11月4 09:10 lsx.txt.bz2

-rw-r--r--  1 root root 46K 11月4 08:44 lsx.txt.gz

-rw-r--r--  1 root root 42K 11月4 09:09 lsx.txt.xz

xz -d 1.txt.xz / unxz 1.txt.xz

[root@lsx1 ~]# xz -d lsx.txt.xz //解压,压缩包消失

[root@lsx1 ~]# ll -h

-rw-r--r--  1 root root 169K 11月4 09:09 lsx.txt

-rw-r--r--  1 root root  43K 11月4 09:10 lsx.txt.bz2

-rw-r--r--  1 root root  46K 11月4 08:44 lsx.txt.gz

xz -# 1.txt  //#范围2021年05月14日,默认9压缩比:xz压缩最严谨,次bz2,gz

[root@lsx1 ~]# xz -9 lsx.txt

[root@lsx1 ~]# ll -h

-rw-r--r--  1 root root 43K 11月4 09:10 lsx.txt.bz2

-rw-r--r--  1 root root 46K 11月4 08:44 lsx.txt.gz

-rw-r--r--  1 root root 42K 11月4 09:09 lsx.txt.xz

不能压缩目录

[root@lsx1 ~]# xz lsx

xz: lsx: Is a directory, skipping

xzcat 1.txt.xz

[root@lsx1 ~]# xzcat lsx.txt.xz //查看文件内容

xz -c 1.txt > /root/1.txt.xz

[root@lsx1 ~]# xz -c lsx.txt>./lsx.txt.xz //压缩。-c源文件不消失,需指定压缩文件

[root@lsx1 ~]# ls

lsx.txt  lsx.txt.xz

xz -d -c /root/1.txt.xz > 1.txt.new3

[root@lsx1 ~]# xz -dc lsx.txt.xz > lsx.txt.xz.new  //解压缩,-c指定解压缩之后文件,压缩包不消失

[root@lsx1 ~]# ls

lsx.txt.xz

lsx.txt.xz.new

本文转自 虾米的春天 51CTO博客,原文链接:http://blog.51cto.com/lsxme/1980533,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值