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

61 压缩打包介绍

压缩打包介绍、gzip、bzip2、xz压缩工具_第1张图片
常见压缩文件类型

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

6.2 gzip压缩工具

压缩打包介绍、gzip、bzip2、xz压缩工具_第2张图片
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更厉害


压缩打包介绍、gzip、bzip2、xz压缩工具_第3张图片
压缩的更厉害的压缩工具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压缩工具

压缩打包介绍、gzip、bzip2、xz压缩工具_第4张图片
基本用法都一样
[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

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

你可能感兴趣的:(压缩打包介绍、gzip、bzip2、xz压缩工具)