6.1-6.7 压缩打包相关

6.1 压缩打包介绍

常见的压缩文件类型:

Windows :     .rar      .zip      .7z

Linux : .zip  .gz    .bz2  .xz    .tar.gz    .tar.bz2   .tar.xz


6.2 gzip压缩工具

压缩级别:1-9级别(压缩级别越大,占用的cup资源越大!)

默认压缩级别:6级别

gzip压缩工具:只能压缩文件,不支持压缩目录!!!

@查看文件内容行数: wc -l  文件名

[root@hao-01 mulu1]# wc -l 22.txt

1. gzip压缩 gzip 原文件

gzip压缩工具会把原文件替换掉)

[root@hao-01 ~]# gzip 22.txt

2. 查看gz格式的压缩文件:

gzip压缩工具会把原文件替换掉,生成.gz后缀格式的压缩文件!)

[root@hao-01 ~]# ls 22.txt.gz

3. 查看.gz压缩文件内容: zcat  压缩文件名

[root@hao-01 ~]# zcat 22.txt.gz

4gzip解压: gzip  -d  .gz压缩文件

[root@hao-01 ~]# gzip -d 22.txt.gz

5. gzip解压: gunzip .gz压缩文件

[root@hao-01 ~]# gunzip 22.txt.gz

6. gzip压缩原文件,同时原文件不被替换掉:  

gzip -c 原文件 > 压缩文件名

[root@hao-01 ~]# gzip -c 22.txt > 22.txt.gz

7. gzip解压.gz压缩文件,同时.gz压缩文件不被替换掉:

gzip -d -c  .gz压缩文件 解压文件名

[root@hao-01 ~]# gzip -d -c 22.txt.gz > 22.txt


6.3 bzip2压缩工具

yun安装bzip2压缩工具:

[root@hao-01 ~]# yum install -y bzip2

压缩级别:1-9级别(压缩级别越大,占用的cup资源越大!)

默认压缩级别:6级别

bzip2压缩工具:只能压缩文件,不支持压缩目录!!!

查看文件格式

[root@hao-01 ~]# file 22.txt.gz

clipboard.png

1. bzip2压缩 bzip2 原文件

bzip2压缩工具会把原文件替换掉)

[root@hao-01 ~]# bzip2 22.txt

2. 查看bz2格式的压缩文件:

bzip2压缩工具会把原文件替换掉,生成.bz2后缀的压缩文件!)

[root@hao-01 ~]# ls 22.txt.bz2

3. 查看.bz2压缩文件内容: bzcat  压缩文件名

[root@hao-01 ~]# bzcat 22.txt.bz2

4. bzip2解压: bzip2  -d  .bz2压缩文件

[root@hao-01 ~]# bzip2 -d 22.txt.bz2

5. bzip2解压: bunzip2 .bz2压缩文件

[root@hao-01 ~]# bunzip2 22.txt.bz2

6. bzip2压缩文件,同时文件不被替换掉:  

bzip2 -c 原文件 > 压缩文件名

[root@hao-01 ~]# bzip2 -c 22.txt > 22.txt.bz2

7. bzip2解压.bz2压缩文件,同时.bz2压缩文件不被替换掉:

bzip2 -d -c  .bz2压缩文件 解压文件名

[root@hao-01 ~]# bzip2 -d -c 22.txt.bz2 > 22.txt


6.4 xz压缩工具

1. xz压缩 xz 原文件

xz压缩工具会把原文件替换掉)

[root@hao-01 ~]# xz 22.txt

2. 查看xz格式的压缩文件:

xz压缩工具会把原文件替换掉,生成.xz后缀的压缩文件!)

[root@hao-01 ~]# ls 22.txt.xz

3. 查看.xz压缩文件内容: xz  压缩文件名

[root@hao-01 ~]# xzcat 22.txt.xz

4. xz解压: xz  -d  .bz2压缩文件

[root@hao-01 ~]# xz -d 22.txt.xz

5. xz解压: unxz .xz压缩文件

[root@hao-01 ~]# unxz 22.txt.xz

6. xz压缩文件,同时文件不被替换掉:  

xz -c 原文件 > 压缩文件名

[root@hao-01 ~]# xz -c 22.txt > 22.txt.xz

7. xz解压.xz压缩文件,同时.xz压缩文件不被替换掉:

xz -d -c  .xz压缩文件 解压文件名

[root@hao-01 ~]# xz -d -c 22.txt.xz > 22.txt


6.5 zip压缩工具

yum安装zip压缩工具:

[root@hao-01 ~]# yum install -y zip

1. zip压缩文件zip 压缩文件名 原文件

[root@hao-01 ~]# zip hao.txt.zip hao.txt

2. zip压缩目录zip -r   压缩目录名 原目录

[root@hao-01 ~]# zip -r mulu1.zip mulu

yum安装zip解压工具:

[root@hao-01 ~]# yum install -y unzip

3. zip解压文件unzip .zip压缩文件

[root@hao-01 ~]# unzip hao.txt.zip

QQ截图20180528101854.png

4. zip解压文件,同时解压到指定路径

unzip .zip压缩文件  -d 解压指定路径

[root@hao-01 ~]# unzip  hao.txt.zip   -d /tmp

5. zip解压目录unzip .zip目录压缩包

[root@hao-01 ~]# unzip mulu.zip

6. zip解压目录,同时解压到指定路径

unzip .zip目录压缩包  -d 解压指定路径

[root@hao-01 ~]# unzip  mulu.zip   -d /tmp

7. 列出zip目录压缩包 文件列表

unzip -l .zip目录压缩包

[root@hao-01 ~]# unzip -l mulu.zip


6.6 tar打包

1. tar打包目录tar -cvf   目录包名   原目录

(v 的作用,可视打包过程,可以不添加!)

[root@hao-01 ~]# tar -cvf mulu.tar mulu1

2. tar解包.tar包tar -xvf .tar包  

[root@hao-01 ~]# tar -xvf mulu.tar

3. tar同时打包目录文件: tar -cvf 目录包名  原目录  文件

[root@hao-01 ~]# tar -cvf  mulu.tar mulu   hao.txt

4. 查看.tar目录包 文件列表: tar -tf tar目录包

[root@hao-01 ~]# tar -tf mulu.tar

5. tar打包目录,同时过滤目录中的文件目录不进行打包!

tar -cvf 目录包名  --exclude 过滤文件  --exclude 过滤目录  原目录

[root@hao-01 ~]# tar -cvf  mulu.tar   --exclude 22.txt   --exclude mulu3    mulu

6. tar打包目录,同时过滤目录中的所有后缀带有.txt的文件 不进行打包!

tar -cvf 目录包名  --exclude ".txt" 原目录

[root@hao-01 ~]# tar -cvf mulu.txt   --exclude ".txt"    mulu


6.7 打包并压缩

tar打包并gzip压缩

1. tar打包gzip压缩

tar -zcvf .tar.gz打包压缩包名  文件  原目录

[root@hao-01 ~]# tar -zcvf mulu.tar.gz  hao.txt   mulu

2. gzip解压缩tar解包

tar -zxvf  .tar.gz打包压缩包

[root@hao-01 ~]# tar -zxvf  mulu.tar.gz

3. 列出.tar.gz打包压缩包 文件列表:

tar -tf .tar.gz打包压缩包

[root@hao-01 ~]# tar -tf mulu1.tar.gz

tar打包并bzip2压缩

1. tar打包bzip2压缩

tar -jcvf .tar.bz2打包压缩包名  文件  原目录

[root@hao-01 ~]# tar -jcvf mulu.tar.bz2  hao.txt   mulu

2. gzip解压缩bzip2解包

tar -jxvf  .tar.bz2打包压缩包

[root@hao-01 ~]# tar -jxvf  mulu.tar.bz2

3. 列出.tar.bzip2打包压缩包 文件列表:

tar -tf .tar.bz2打包压缩包

[root@hao-01 ~]# tar -tf mulu1.tar.bz2

tar打包并xz压缩

1. tar打包并xz压缩

tar -Jcvf .tar.xz打包压缩包名  文件  原目录

[root@hao-01 ~]# tar -Jcvf mulu.tar.xz  hao.txt   mulu

2. gzip解压缩并xz解包

tar -Jxvf  .tar.xz打包压缩包

[root@hao-01 ~]# tar -Jxvf  mulu.tar.xz

3. 列出.tar.xz打包压缩包 文件列表:

tar -tf .tar.xz打包压缩包

[root@hao-01 ~]# tar -tf mulu1.tar.xz


扩展:

 http://ask.apelearn.com/question/5435

猜你喜欢

转载自blog.51cto.com/13530586/2120996
6.7
6.1
今日推荐