• 6.1 压缩打包介绍
  • 6.2 gzip压缩工具
  • 6.3 bzip2压缩工具
  • 6.4 xz压缩工具

常见的压缩文件格式

windows     .rar  .zip  .7z

linux         .zip,.gz,.bz2,.xz,.tar.gz,.tar.bz2,.tar.xz

  • gzip压缩工具

gzip  1.txt

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

gzip -#1.txt  //#范围1-9默认6

不能解压缩目录

zcat 1.txt.gz

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

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

先创建一个大的文件1.txt,将文件.conf 的 追加到1.txt文件

[root@localhost d6z]# find /etc/ -type f -name "*conf"  -exec cat {} >> 1.txt \;

查看字符个数

wc 1.txt

[root@localhost d6z]# wc 1.txt

38280  154812 1419540 1.txt

用gzip 压缩1.txt

gzip 1.txt

[root@localhost d6z]# gzip 1.txt

[root@localhost d6z]# ls -lh

总用量 340K

-rw-r--r--. 1 root root 340K 12月 18 21:07 1.txt.gz

查看1.txt.gz大小

[root@localhost d6z]# du -sh 1.txt.gz

340K 1.txt.gz

解压文件

gzip  -d 1.txt .gz

[root@localhost d6z]# gzip -d 1.txt.gz

[root@localhost d6z]# du -sh 1.txt

1.4M 1.txt

查看多少行,多少字符个数

[root@localhost d6z]# wc 1.txt

38280  154812 1419540 1.txt

压缩级别:1到9;

1级别压缩率最低,9压缩率最高,压缩级别可以保持默认

gzip -1 1.txt

[root@localhost d6z]# gzip -1 1.txt

[root@localhost d6z]# du -sh 1.txt.gz

396K 1.txt.gz

也可以用gunzip解压.gz

gunzip 1.txt.gz

[root@localhost d6z]# gunzip 1.txt.gz

[root@localhost d6z]# du -sh 1.txt

1.4M 1.txt

压缩到9级别 gzip -9 1.txt

[root@localhost d6z]# gzip -9 1.txt

[root@localhost d6z]# du -sh 1.txt.gz

340K 1.txt.gz

查看压缩文件信息

file 1.txt.gz

[root@localhost d6z]# file 1.txt.gz

1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Mon Dec 18 21:07:40 2017, max compression

查看压缩文件的内容

zcat 1.txt.gz 先解压后cat

gzip 不能压缩目录

gzip -c  1.txt > /tmp/1.txt.gz   解压文件,并保存压缩后的文件.gz 到一个地方;其中(“>”表示重定向,-c表示解压后,并保存压缩文件)

[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]# file !$

file /tmp/1.txt.gz

/tmp/1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Mon Dec 18 21:07:40 2017

同样解压缩也是可以的。解压文件并保存1.txt.gz 到/tmp/d6z/2.txt

gzip -d  -c /tmp/1.xtx.gz > /tmp/d6z/2.txt

[root@localhost d6z]# gunzip -d -c  /tmp/1.txt.gz > /tmp/2.txt

[root@localhost d6z]# ls /tmp/2.txt

/tmp/2.txt

bzip2压缩工具

复习gzip:

gzip 1.txt

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

gzip -# 1.txt  //# 表示范围 1-9,默认6

不能压缩目录

zcat 1.txt.gz //查看压缩包里面的内容,意思是先解压后cat

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

gunzip -c /root/1.txt.gz >/tmp/1.txt.new  //其中 >号表示重定向

bzip2压缩能力比gzip 强

[root@localhost tmp]# du -sh 1.txt

2.8M 1.txt

压缩:bzip2     1.txt

du -sh 1.txt.bz2

[root@localhost tmp]# du -sh 1.txt.bz2

136K 1.txt.bz2

解压:

[root@localhost tmp]# bunzip2 1.txt.bz2

[root@localhost tmp]# bzip2 -d 1.txt.bz2

不支持压缩目录

用-c 指定压缩到目录:将1.txt 压缩到/tmp目录下

[root@localhost ~]# bzip2 -c /tmp/1.txt > /tmp/1.txt.bz2

将压缩包指定解压到目录:

[root@localhost ~]# bzip2 -d -c /tmp/1.txt.bz2  > 2.txt

[root@localhost ~]# ls

2.txt  anaconda-ks.cfg

bzip2 默认压缩级别为9,也不需要指定级别

[root@localhost ~]# du -sh

140K .

[root@localhost ~]# bzip2 -9 2.txt

[root@localhost ~]# du -sh

36K .

file查看文件的格式

[root@localhost ~]# file 2.txt.bz2

2.txt.bz2: bzip2 compressed data, block size = 900k

有时候把压缩文件重名了.txt

例如:

[root@localhost ~]# mv 2.txt.bz2 2.txt

这时候可以用file命令查看文件类型

[root@localhost ~]# file 2.txt

2.txt: bzip2 compressed data, block size = 900k

bzcat也可以查看文件内容:(就是先解压后cat查看文件内容)

bzcat 1.txt.bz2

  • xz压缩

[root@localhost ~]# du -sh

144K .

[root@localhost ~]# xz 2.txt

[root@localhost ~]# du -sh

40K .

xz 默认压缩级别为9,最高。

压缩率:

xz>bzip2>gzip

解压:

xz -d 2.txt.xz

或者 unxz 2.txt.xz

指定压缩文件到某个目录

xz  -c   2.txt  > /tmp/2.txt.xz

指定解压文件到某个目录

xz  -d  -c  /tmp/2.txt.xz  >  /root/3.txt

也可以查看压缩文件的内容

xzcat  /tmp/2.txt.xz

压缩打包介绍/gzip压缩工具/bzip2压缩工具/xz压缩工具的更多相关文章

  1. 压缩打包介绍、gzip、bzip2、xz压缩工具

    第5周第1次课(4月16日) 课程内容: 6.1 压缩打包介绍6.2 gzip压缩工具6.3 bzip2压缩工具6.4 xz压缩工具 6.1 压缩打包介绍 为什么要给文件进行压缩呢?首先压缩和不压缩空 ...

  2. Linux centosVMware 压缩打包介绍、gzip压缩工具、bzip2压缩工具、xz压缩工具。

    一.压缩打包介绍 Lnux下常见的压缩文件通常是.tar.gz模式,还有.tar..gz..bz2..zip..tar.bz2..tar.xz. .gz:表示由gzip压缩工具压缩的文件 .bz2:表 ...

  3. 简单了解gzip、bzip2、xz

    压缩工具gzip.bzip2.xz分别对应压缩格式.gz..bz2..xz.不过tar命令已经可以满足大部分使用,所以这些格式只简单了解一下.gzip压缩速度最快,xz压缩率最高,bz2适中.一般这三 ...

  4. 压缩工具gzip、bzip2、xz的使用

    2019独角兽企业重金招聘Python工程师标准>>> 本文使用 为了要压缩 常见压缩格式 压缩工具 gzip压缩工具 bz2压缩工具 xz压缩工具 为什么要压缩 为什么要压缩?文件 ...

  5. 文档压缩 | gzip、bzip2、xz

    6.文档的压缩与打包 Linux下常见后缀名所对应的的压缩工具 .gz 表示由gzip压缩工具压缩的文件 .bz2 表示由bzip2压缩工具压缩的文件 .tar 表示由tar打包程序打包的文件(tar ...

  6. 文件与文件系统的压缩与打包 tar gzip bzip2

    1:linux下常见的压缩文件后缀: .gz .zip .bz2 打包后的: .tar.gz .tar.zip .tar.bz2 2:gzip: 压缩:gzip file 解压:gunzip file ...

  7. Linux压缩打包方法连载之三:bzip2, bzcat 命令

    Linux压缩打包方法有多种,本文集中讲解了bzip2, bzcat 命令的使用.案例说明,例如# 与 gzip 同样的,都是在计算压缩比的参数,-9 最佳,-1 最快. AD: 我们遇见Linux压 ...

  8. Linux中常用压缩打包工具

    Linux中常用压缩打包工具 压缩打包是常用的功能,在linux中目前常用的压缩工具有gzip,bzip2以及后起之秀xz.本文将介绍如下的工具常见压缩.解压缩工具以及打包工具tar. gzip2 直 ...

  9. Linux文件压缩/打包/解压

    在Linux日常维护中,经常需要备份同步一些比较重要的文件,而在传输过程中如果文件比较大往往会非常慢,而且还会非常占用空间,这时候就需要我们使用压缩工具对大文件进行压缩打包,下面我们来介绍一下常用的压 ...

随机推荐

  1. ios9 之后使用CFNumberGetValue出错

    将编译源类型设置为根据文件而定:

  2. [转]MySQL实现分页查询

    原文地址:https://blog.csdn.net/starleejay/article/details/78802610 limit 基本实现方式 一般情况下,客户端通过传递 pageNo(页码) ...

  3. [转]Extjs中的迭代方法

    原文地址:http://www.veryhuo.com/a/view/36701.html EXTJS 有很多的迭代方法,例如,你也许已知道的Ext.each,但还有另外一些不为人知且很有用的方法.首 ...

  4. Thinkphp动态切换主题

    'DEFAULT_THEME' => '2014', 'TMPL_DETECT_THEME' => true, // 自动侦测模板主题 'THEME_LIST' => '2012,2 ...

  5. Free-form语言

    在计算机编程领域,程序指令文本中的字符在『纸面』上所处的位置无关紧要 - 不像老式的穿孔卡片系统(punched card system)程序指令文本需要放置在指定列,这种编程语言就可算是自由形式语言 ...

  6. Ext.dom.Element 常用方法解析

    Ext.dom.Element 常用方法解析 Ext.Element,Ext.core.Elemen,Ext.dom.Element 这几个类都是一个类,在EXT当中给起了别名而已,这个类到作用主要是 ...

  7. MVC的JavaScriptResult使用

    JavaScriptResult的使用有两个必要的前提: 1.Ajax 2.jquery.unobtrusive-ajax.js 使用代码示例 controller public ActionResu ...

  8. android开发(28) 做个 指南针 应用

    参考网上的资料,做了个指南针应用玩玩. 步骤: 1.获得 SensorManager. mSensorManager = (SensorManager) getSystemService(SENSOR ...

  9. Remove 以及dorp做实验验证MongoDB删除文档后索引是否会自动删除

    下面是实验步骤: > db.things.find(){ "_id" : ObjectId("5652d71a1524dc14663060e8"), &q ...

  10. AngularJS Notes

    ng-app The ng-app directive tells AngularJS that the <div> element is the "owner" of ...