• 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. 正益无线首页jQuery焦点图

    分享一款正益无线首页jQuery焦点图,带索引按钮,自动轮播切换特效焦点图代码. 在线预览   源码下载 实现的代码. html代码: <div id="slideBox" ...

  2. 基于jQuery环形图标菜单旋转切换特效

    分享一款基于jQuery环形图标旋转切换特效.这是一款鼠标点击图标菜单圆形顺时针或者逆时针旋转切换代码.效果图如下: 在线预览   源码下载 实现的代码. js代码: /* 图片地址可以是相对路径或绝 ...

  3. Domain应用之 根据某个Many2one的对象的 X2many对象 过滤

    如果两者都是many2one类型的对象,过滤非常简单,在xml中添加domain过滤即可,比如 国家.省市之间的联动关系. 如果想要根据某个对象的X2many类型的字段进行过滤该如何去做呢? 答案是利 ...

  4. [TestLink]testlink安装

    转自:http://www.51testing.com/html/25/465025-3711140.html bitnami参考:https://bitnami.com/stack/testlink ...

  5. spring websocket + stomp 实现广播通信和一对一通信<转>

    spring对于基于stomp协议的websocket通信,其官网上面有一个guide,但是根据guide你只能写出来广播方式的通信,不能实现一对一的通信,这篇文章在这里把广播和一对一一起整理一下给大 ...

  6. hadoop rebalance

    之前一直没做过rebalance,以为速度很快,结果大意了,等到磁盘达到90%的时候,才开始做rebalance. 默认的从日志中可以看到总共需要迁移1.89T,但是每次只移动40G大小的量. 然后查 ...

  7. Linux查看cpu个数

    [root@lidongbo~]# cat /proc/cpuinfo processor       : 0 vendor_id       : GenuineIntel cpu family    ...

  8. Asp.net MVC 自定义异常处理类

    using ElegantWM.Common; using System; using System.Collections.Generic; using System.Linq; using Sys ...

  9. compareTo返回值为-1 、 1 、 0 的排序问题

    1.什么是Comparable接口 此接口强行对实现它的每个类的对象进行整体排序.此排序被称为该类的自然排序 ,类的 compareTo 方法被称为它的自然比较方法 .实现此接口的对象列表(和数组)可 ...

  10. PHP判断字符串的包含

    PHP语言是一个功能强大的嵌入式HTML脚本语言,它的易用性让许多程序员选择使用.PHP判断字符串的包含,可以使用PHP的内置函数strstr,strpos,stristr直接进行判断.也可以通过ex ...