700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 压缩工具gzip bzip2 xz

压缩工具gzip bzip2 xz

时间:2023-10-03 02:06:15

相关推荐

压缩工具gzip bzip2 xz

压缩打包介绍

使用压缩工具的好处:

使用压缩文件,不仅可以节省磁盘空间,而且在传输时还能节省网络宽带。

我们通常讲的家用宽带和机房宽带100M是有区别的:

机房宽带的上行和下行都是100M,所以价格昂贵,家用宽带下行是100M,但是上行往往只有10M-20M

Linux下最常见的压缩文件是.tar.gz格式,还有.zip,.gz,.bz2,.xz,.tar.bz2,.tar.xz等。.gz 表示由gzip压缩工具压缩的文件。.bz2 表示由bzip2压缩工具压缩的文件。.tar 表示由tar打包程序打包的文件(tar没有压缩功能,只是把一个目录合并成一个文件).tar.gz 先打包,在由gzip压缩.tar.bz2 先打包,在由bzip2压缩.tar.xz 先打包,在由xz压缩

gzip压缩工具

格式:gzip [参数] filename -d是解压缩。

gzip -# filename //#范围1-9,默认6gzip 不能压缩目录gzip filename 压缩文件,暂不支持压缩目录,压缩后源文件消失gzip -d filename.gz 解压文件,解压后,源压缩文件消失gunzip filename.gz 解压文件, 解压后,源压缩文件消失gzip –c filename > /tmp/filename.gz指定压缩文件路径,并且源文件存在gzip –d –c /tmp/filename.gz > ./filename 解压文件到那个路径下,并且源压缩文件存在。gunzip –c /tmp/filename.gz > ./filename 解压文件到那个路径下,并且源压缩文件存在。zcat 1.txt.gz 查看.gz文件file /tmp/1.txt.gz 查看文件的属性

例子:查找/etc/下后缀为.conf的文件,并将它的内容追加到文件1.txt中,并且压缩它,然后再解压。

[root@localhost d6z]# find /etc/ -type f -name "*.conf" -exec cat {} >>1.txt \;[root@localhost d6z]# du -sh 1.txt4.0M1.txt//这里要注意一下,这个大小不太准确,这里多次追加会看到文件,du -sh 1.txt查看的文件数值不同,但在多次查看,文件大小会恢复正常。(跳转数值较大比,是因为这个文件本身存在很多空隙,最后在压缩并解压后,会发现大小会有不同) [root@localhost d6z]# gzip 1.txt[root@localhost d6z]# du -sh 1.txt.gz664K1.txt.gz[root@localhost d6z]# gzip -d 1.txt.gz[root@localhost d6z]# du -sh 1.txt2.5M1.txt[root@localhost d6z]# gzip 1.txt[root@localhost d6z]# du -sh 1.txt.gz664K1.txt.gz[root@localhost d6z]# gunzip 1.txt.gz[root@localhost d6z]# du -sh 1.txt2.5M1.txt

压缩文件1.txt,并且将压缩文件放到/tmp/下

[root@localhost d6z]# gzip -c 1.txt > /tmp/1.txt.gz[root@localhost d6z]# ls1.txt[root@localhost d6z]# ls /tmp/1.txt.gz/tmp/1.txt.gz[root@localhost d6z]# du -sh /tmp/1.txt.gz664K/tmp/1.txt.gz

解压文件1.txt.gz ,存放到当前目录下,命名为2.txt

[root@localhost d6z]# gzip -d -c /tmp/1.txt.gz > ./2.txt[root@localhost d6z]# ls1.txt 2.txt[root@localhost d6z]# wc -l 1.txt 2.txt64790 1.txt64790 2.txt129580 总用量[root@localhost d6z]# du -sh 1.txt 2.txt2.5M1.txt2.5M2.txt[root@localhost d6z]# ls /tmp/1.txt.gz/tmp/1.txt.gz

查看压缩文件1.txt.gz的内容,因为内容比较多,这里就不粘贴出来了。

[root@localhost d6z]# zcat /tmp/1.txt.gz

file /tmp/1.txt.gz 查看属性,

[root@localhost d6z]# file /tmp/1.txt.gz/tmp/1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Thu Nov 9 22:33:33 /tmp/1.txt.gz 压缩数据是1.txt,基于unix平台,最后修改时间是11月9日星期四

bzip2压缩工具

bzip命令的格式:bzip2 [-dz] filename ,压缩文件时加不加-z都一样,-d 解压缩。

bzip比gzip压缩更小,所耗费的CPU资源也最大(压缩的文件也是最小的)

bzip2 1.txt / bzip2 -z 1.txt //压缩文件bzip2 -d 1.txt.bz2 / bunzip2 1.txt.bz2 //解压文件bzip -# 1.txt //#范围1-9,默认9不能压缩目录bzcat 1.txt.bz2 //查看压缩文件bzip2 -c 1.txt > /root/1.txt.bz2 //指定压缩文件路径,并且源文件存在bzip2 -c -d /root/1.txt.bz2 > /tmp/1.txt.new2 //解压文件到指定路径下,并且源压缩文件存在File 1.txt.bz2 查看文件属性

第一次使用bzip2命令时提示没有这个命令,我们用yum安装一下

[root@localhost d6z]# bzip2 1.txt-bash: bzip2: 未找到命令[root@linux-128 d6z]# yum install -y bzip2

压缩文件1.txt

[root@localhost d6z]# bzip2 1.txt[root@localhost d6z]# ls1.txt.bz2 2.txt

解压文件1.txt.gz

[root@localhost d6z]# bzip2 -d 1.txt.bz2[root@localhost d6z]# ls1.txt 2.txt

压缩文件1.txt,并且指定路径,源文件存在

[root@localhost d6z]# bzip2 -c 1.txt > /tmp/1.txt.bz2[root@localhost d6z]# ls /tmp/1.txt.bz2/tmp/1.txt.bz2[root@localhost d6z]# ls1.txt 2.txt

解压文件1.txt.bz2,并且指定路径重名命为3.txt,源文件存在。

[root@localhost d6z]# bzip2 -d -c /tmp/1.txt.bz2 > ./3.txt[root@localhost d6z]# ls1.txt 2.txt 3.txt[root@linux-128 d6z]# ls /tmp/1.txt.bz2/tmp/1.txt.bz2

查看压缩文件1.txt.bz2 内容

[root@localhost d6z]# bzcat /tmp/1.txt.bz2

查看文件1.txt.bz2的属性。

[root@localhost d6z]# file /tmp/1.txt.bz2/tmp/1.txt.bz2: bzip2 compressed data, block size = 900k //bzip2压缩数据,大小为900k

xz压缩工具

xz命令格式:xz[-zd] filename 压缩文件加不加-z都可以,-d解压缩。

xz压缩文件比bzip2更小,所耗费的CPU资源也最大(压缩的文件也是最小的)

xz 1.txt / xz -z 1.txt //压缩文件

xz -d 1.txt.xz / unxz 1.txt.xz //解压缩文件

xz -# 1.txt //#范围1-9,默认9

不能压缩目录

xzcat 1.txt.xz //查看压缩文件内容

xz -c 1.txt > /root/1.txt.xz //指定压缩文件路径,并且源文件存在

xz -d -c /root/1.txt.xz > 1.txt.new3 //解压文件到指定路径下,并且源压缩文件存在

file 1.txt.xz查看文件属性

压缩文件1.txt

root@linux-128 d6z]# xz 1.txt[root@linux-128 d6z]# ls1.txt.xz 2.txt 3.txt

解压文件1.txt.xz

[root@localhost d6z]# xz -d 1.txt.xz[root@localhost d6z]# ls1.txt 2.txt 3.txt

压缩文件1.txt,并且指定路径,源文件存在

[root@localhost d6z]# xz -c 1.txt > /tmp/1.txt.xz[root@localhost d6z]# ls1.txt 2.txt 3.txt[root@localhost d6z]# ls /tmp/1.txt.xz/tmp/1.txt.xz

解压文件1.txt.bz2,并且指定路径重名命为4.txt,源文件存在。

[root@localhost d6z]# xz -d -c /tmp/1.txt.xz > ./4.txt[root@localhost d6z]# ls1.txt 2.txt 3.txt 4.txt[root@localhost d6z]# ls /tmp/1.txt.xz/tmp/1.txt.xz

file 1.txz.xz

[root@localhost d6z]# file /tmp/1.txt.xz/tmp/1.txt.xz: XZ compressed data //xz压缩数据。

1.txt.xz<1.txt.bz2<1.txt.gz 说明xz压缩更严谨,但是所耗费cpu资源最大。

[root@localhost d6z]# du -sh /tmp/1.txt.gz /tmp/1.txt.bz2 /tmp/1.txt.xz664K/tmp/1.txt.gz260K/tmp/1.txt.bz260K/tmp/1.txt.xz

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。