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

61 压缩打包介绍

常见压缩文件类型

压缩过后文件大小降低可以减少带宽量

6.2 gzip压缩工具

gzip压缩工具
[root@localhost d6z]# find /etc/ -type f -name "*conf" -exec cat {} >> 1.txt \;(将所有/etc/下的conf文件写入1.txt)
[root@localhost d6z]# ls -lh
总用量 212K
-rw-r--r--. 1 root root 211K 1月   9 11:56 1.txt
[root@localhost d6z]# gzip 1.txt(压缩1.txt)
[root@localhost d6z]# ls -lh
总用量 56K
-rw-r--r--. 1 root root 54K 1月   9 11:56 1.txt.gz
[root@localhost d6z]# gzip -d 1.txt.gz (解压)
[root@localhost d6z]# ls -lh
总用量 212K
-rw-r--r--. 1 root root 211K 1月   9 11:56 1.txt
[root@localhost d6z]# gzip -1 1.txt (指定压缩级别,范围1-9,默认6,1级别为压缩的最不厉害的,一般默认)
[root@localhost d6z]# ls -lh
总用量 64K
-rw-r--r--. 1 root root 63K 1月   9 11:56 1.txt.gz 
[root@localhost d6z]# gunzip 1.txt.gz 
[root@localhost d6z]# ls -lh
总用量 212K
-rw-r--r--. 1 root root 211K 1月   9 11:56 1.txt
[root@localhost d6z]# zcat 1.txt.gz(查看压缩文件中的内容)
[root@localhost d6z]# gzip -c 1.txt > /root/d6z/1.txt.gz(指定压缩路径及保存压缩名称,并保留原文件)
[root@localhost d6z]# ls
1.txt  1.txt.gz
[root@localhost d6z]# gunzip -c 1.txt.gz > /root/d6z/2.txt(指定解压路径及保存解压缩名称)
[root@localhost d6z]# ls
1.txt  2.txt

gzip不能压缩目录

63 bzip2压缩工具

相较gzip压缩bizp2更厉害


压缩的更厉害的压缩工具bzip2
[root@localhost d6z]# yum install -y bzip2(安装)
[root@localhost d6z]# bzip2 1.txt 
[root@localhost d6z]# ls -lh
总用量 260K
-rw-r--r--. 1 root root  48K 1月  10 09:55 1.txt.bz2
-rw-r--r--. 1 root root 211K 1月  10 09:56 2.txt
[root@localhost d6z]# bzip2 -d 1.txt.bz2 
[root@localhost d6z]# ls -lh
总用量 424K
-rw-r--r--. 1 root root 211K 1月  10 09:55 1.txt
-rw-r--r--. 1 root root 211K 1月  10 09:56 2.txt
[root@localhost d6z]# bzip2 -d 1.txt.bz2 
[root@localhost d6z]# ls -lh
总用量 424K
-rw-r--r--. 1 root root 211K 1月  10 09:55 1.txt
-rw-r--r--. 1 root root 211K 1月  10 09:56 2.txt
[root@localhost d6z]# bzip2 -c 1.txt > /root/d6z/1.txt.bz2 
[root@localhost d6z]# ls -lh
总用量 472K
-rw-r--r--. 1 root root 211K 1月  10 09:55 1.txt
-rw-r--r--. 1 root root  48K 1月  10 10:33 1.txt.bz2
-rw-r--r--. 1 root root 211K 1月  10 09:56 2.txt
[root@localhost d6z]# bunzip2 -c 1.txt.bz2 > /root/d6z/3.txt
[root@localhost d6z]# ls -lh
总用量 684K
-rw-r--r--. 1 root root 211K 1月  10 09:55 1.txt
-rw-r--r--. 1 root root  48K 1月  10 10:33 1.txt.bz2
-rw-r--r--. 1 root root 211K 1月  10 09:56 2.txt
-rw-r--r--. 1 root root 211K 1月  10 10:36 3.txt
[root@localhost d6z]# file 1.txt.bz2 
1.txt.bz2: bzip2 compressed data, block size = 900k(查看文件格式)

bzip2也不支持压缩目录

64 xz压缩工具

基本用法都一样
[root@localhost d6z]# xz -c 1.txt > /root/d6z/1.txt.xz
[root@localhost d6z]# ls
1.txt  1.txt.xz
[root@localhost d6z]# xz -d -c 1.txt.xz > /root/d6z/2.txt
[root@localhost d6z]# ls
1.txt  1.txt.xz  2.txt

压缩得程度最大
不支持压缩目录

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 为什么要整理一下Linux下的打包和压缩工具呢?原因很简单,因为遇到问题了:游戏服务器可执行文件、配置和各种资源文...
    davidpp阅读 13,358评论 0 18
  • gzip, bzip2, xz, tar 一、为什么要压缩? 1. 为了节省更多的磁盘空间,降低磁盘的使用率 2....
    魏镇坪阅读 5,423评论 0 1
  • 压缩文件的用途与技术 压缩文件使文件大小减低,降低磁盘使用量。还可以分成数个小型文件,方便携带。常用于网络数据传输...
    taosilly阅读 5,231评论 0 1
  • 压缩打包介绍 在windows下我们常见的压缩包格式有;.rar .zip .7z 而在linux我们常见的有;....
    hch004阅读 2,812评论 0 0
  • linux资料总章2.1 1.0写的不好抱歉 但是2.0已经改了很多 但是错误还是无法避免 以后资料会慢慢更新 大...
    数据革命阅读 14,186评论 2 33