压缩工具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,默认6
- gzip 不能压缩目录
- 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.txt
4.0M 1.txt //这里要注意一下,这个大小不太准确,这里多次追加会看到文件,du -sh 1.txt查看的文件数值不同,但在多次查看,文件大小会恢复正常。(跳转数值较大比,是因为这个文件本身存在很多空隙,最后在压缩并解压后,会发现大小会有不同)
[root@localhost d6z]# gzip 1.txt
[root@localhost d6z]# du -sh 1.txt.gz
664K 1.txt.gz
[root@localhost d6z]# gzip -d 1.txt.gz
[root@localhost d6z]# du -sh 1.txt
2.5M 1.txt
[root@localhost d6z]# gzip 1.txt
[root@localhost d6z]# du -sh 1.txt.gz
664K 1.txt.gz
[root@localhost d6z]# gunzip 1.txt.gz
[root@localhost d6z]# du -sh 1.txt
2.5M 1.txt
- 压缩文件1.txt,并且将压缩文件放到/tmp/下
[root@localhost d6z]# gzip -c 1.txt > /tmp/1.txt.gz
[root@localhost d6z]# ls
1.txt
[root@localhost d6z]# ls /tmp/1.txt.gz
/tmp/1.txt.gz
[root@localhost d6z]# du -sh /tmp/1.txt.gz
664K /tmp/1.txt.gz
- 解压文件1.txt.gz ,存放到当前目录下,命名为2.txt
[root@localhost d6z]# gzip -d -c /tmp/1.txt.gz > ./2.txt
[root@localhost d6z]# ls
1.txt 2.txt
[root@localhost d6z]# wc -l 1.txt 2.txt64790 1.txt64790 2.txt129580 总用量
[root@localhost d6z]# du -sh 1.txt 2.txt
2.5M 1.txt
2.5M 2.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 2017
/tmp/1.txt.gz 压缩数据是1.txt,基于unix平台,最后修改时间是2017年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]# ls
1.txt.bz2 2.txt
- 解压文件1.txt.gz
[root@localhost d6z]# bzip2 -d 1.txt.bz2
[root@localhost d6z]# ls
1.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]# ls
1.txt 2.txt
- 解压文件1.txt.bz2,并且指定路径重名命为3.txt,源文件存在。
[root@localhost d6z]# bzip2 -d -c /tmp/1.txt.bz2 > ./3.txt
[root@localhost d6z]# ls
1.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]# ls
1.txt.xz 2.txt 3.txt
- 解压文件1.txt.xz
[root@localhost d6z]# xz -d 1.txt.xz
[root@localhost d6z]# ls
1.txt 2.txt 3.txt
- 压缩文件1.txt,并且指定路径,源文件存在
[root@localhost d6z]# xz -c 1.txt > /tmp/1.txt.xz
[root@localhost d6z]# ls
1.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]# ls
1.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.xz
664K /tmp/1.txt.gz
260K /tmp/1.txt.bz2
60K /tmp/1.txt.xz
压缩工具gzip、bzip2、xz相关推荐
- 压缩工具gzip,bzip2,xz,zip,tar
gzip bzip2 xz 都可以指定压缩等级,都是1到9 ,不能指定解压目录,不过单个文件时可以使用-c参数重定向(-c:将压缩解压后的结果输出到标准输出)实现.unzip可以使用-d指定解压目录 ...
- 4周第4次课 压缩打包介绍 gzip bzip2 xz压缩工具
压缩打包介绍 压缩的目的是为了节约磁盘空间.节约带宽提高传输效率,也利于文件的管理. 常见压缩文件 平台 类型/后缀 Windows .rar .zip .7z Linux .zip .gz .bz2 ...
- 详解的wc find xargs zip gzip bzip2 xz tar sftp命令或者协议
目录 文本内容统计命令 wc 查找文件的路径 find命令详解 xargs zip,unzip命令 gzip和gunzip命令 bzip2.bunzip2命令 xz.unxz命令 tar归档命令压缩 ...
- linux中 gzip bizp2 xz zip怎么用,解压缩
linux 中常用的压缩指令 压缩 gzip bzip2 xz , 解压gunzip unxz bunzip2 解压对应的压缩包 *.tar.gz *.tar.xz *.tar.bz2(由于 ...
- 四周第四次课(1月5日) 6.1 压缩打包介绍 6.2 gzip压缩工具 6.3 bzip2压缩工具 6.4 xz压缩工具...
四周第四次课(1月5日) 6.1 压缩打包介绍 6.2 gzip压缩工具 6.3 bzip2压缩工具 6.4 xz压缩工具 ====================================== ...
- 6.1-6.4 压缩打包介绍,压缩工具gzip,bzip2, xz
6.1 压缩打包介绍 6.2 gzip压缩工具 6.3 bzip2压缩工具 6.4 xz压缩工具 6.1 压缩打包介绍 常见压缩文件 windows .rar .zip .7z Linux .zi ...
- c语言直接实现bzip2压缩方法,Linux普通文件压缩工具gzip、Bzip2、xz
第六章 文件压缩和打包 6.1 压缩打包介绍 Linux环境常见压缩文件类型: .zip,.gz,.bz2,.xz, .tar.gz,.tar.bz2,.tar.xz 压缩打包的目的 方便文件传输 节 ...
- gzip,bzip2压缩工具及tar打包工具
gzip,bzip2压缩工具及tar打包工具 1.gzip压缩工具 1>参数: -c:将参数的数据输出到屏幕上,可通过数据流重定向来处理 ...
- linux bzip2 压缩目录,Linux下压缩工具的区分-gzip,bzip2,tar
总说明: gzip,bzip2只能针对一个文件,而tar是打包没有压缩,可以对多个文件及目录,但tar有gzip及bzip2的压缩功能.bzip2是gzip的升级版,压缩比更高. winrar只能gz ...
- Python数据压缩和存档——zlib/gzip/bzip2/lzma/zip/tar
Python数据压缩和存档--zlib/gzip/bzip2/lzma/zip/tar 原始文档:https://www.yuque.com/lart/ppqg89/gp3q6t 前言 python ...
最新文章
- 2019年《计算机应用基础》,2019年自考《计算机应用基础》模拟练习及答案一
- c++桥接模式bridge
- 4 angular 重构 项目_c# – 将Angular 4添加到ASP.NETCore项目中
- 中国游戏公司研运一体发展专题分析2020
- svn本地没有提交却被还原,找回本地的文件记录的方法
- 单片机 c语言 pwm输出,单片机中PWM程序工作原理图文详解
- spark structured stream的Append模式例子
- 面向项目(十一)—— 库的使用
- Java代码增加回滚6_如何编写取消按钮的代码以撤消/回滚添加和更新正在进行的行4gl...
- C语言练习:hackerrank十五关
- 电力系统学习-电力系统及电力模型
- qt qtableview 刷新列表_qt qtableview基本用法
- H5端关于img居中的一个兼容性bug
- Hexo+Github轻松搭建个人博客
- IDEA启动My Eclipse项目
- V831——脱机实现通信行程卡识别
- RSA解密中文乱码解决,前端加密后端解密
- 信用卡使用的诸多误区、技巧
- 网速正常服务器正常游戏延迟,网速时延多少正常(网络延迟与网速有关吗)
- Java判断经纬度点是否落在指定的区域范围内?
热门文章
- windows版本查询
- python pool 和 quene冲突
- 数学计算机的英语怎么读,calculator是什么意思_calculator怎么读_calculator翻译_用法_发音_词组_同反义词_计算器-新东方在线英语词典...
- JDK8 按List中元素对象的多字段对List进行排序
- VBA分别计算Excel的每一行填充颜色的单元格。把结果写到行最后
- 目前大多数计算机采用的是,计算机专业 选择题8
- 微信支付问题:WeChatNotifyActivity} did not call finish() prior to onResume() completing
- 【转】《基于MFC的OpenGL编程》Part 2 Setting up OpenGL on Windows(1)
- CODEVS 1012
- 过英语计算机目标细化,【计算机专业论文】计算机专业教学改革浅析3篇(共9996字)...