1 压缩 gzip [up17@iZ28dns5aezZ ~]$ gzip 1.txt [up17@iZ28dns5aezZ ~]$ ll total 4 -rw-rw-r-- 1 up17 up1
1 压缩 gzip
[up17@iZ28dns5aezZ ~]$ gzip 1.txt
[up17@iZ28dns5aezZ ~]$ ll
total 4
-rw-rw-r-- 1 up17 up17 26 Sep 22 20:31 1.txt.gz
-rw-rw-r-- 1 up17 up17 0 Sep 22 21:13 2.txt
gzip 压缩,只能把一个或多个文件压缩成.gz文件,然后原来的文件就被自动删除了
2 解压gunzip
[up17@iZ28dns5aezZ ~]$ gunzip 1.txt.gz 2.txt.gz
[up17@iZ28dns5aezZ ~]$ ll
total 0
-rw-rw-r-- 1 up17 up17 0 Sep 22 20:31 1.txt
-rw-rw-r-- 1 up17 up17 0 Sep 22 21:13 2.txt
[up17@iZ28dns5aezZ ~]$
同压缩的gzip相反解压后原来的压缩文件也会被删除
3 打包
压缩和解压都是只能针对文件的,而不能处理文件夹,所以文件夹可以用tar进行打包,然后再压缩
。且打包之后和打包之前的文件/文件夹大小基本一致。
tar -cvf 1_2.tar 1.txt 2.txt
[up17@iZ28dns5aezZ ~]$ ll
total 32
-rw-rw-r-- 1 up17 up17 20480 Sep 22 21:42 1_2.tar
-rw-rw-r-- 1 up17 up17 10240 Sep 22 21:41 1.txt
-rw-rw-r-- 1 up17 up17 0 Sep 22 21:13 2.txt
打包命令的基本格式:tar -cvf packagename filename1 filename2
解包 tar -xvf 1_2.tar
打包和解包 和只之前压缩相比,不会删除原文件
4 归档压缩和解压
归档压缩就是把文件或者文件夹压缩我一个压缩文件,相当也同时做了打包和压缩
tar -cvzf t.tar 1.txt 2.txt
1.txt
2.txt
[up17@iZ28dns5aezZ ~]$ ll
total 16
-rw-rw-r-- 1 up17 up17 10240 Sep 22 21:41 1.txt
-rw-rw-r-- 1 up17 up17 0 Sep 22 21:13 2.txt
-rw-rw-r-- 1 up17 up17 146 Sep 22 21:49 t.tar
可以看到原来1.txt 文件大小10240字节,和2.txt压缩后只有146字节了。压缩效果还是不错的。
归档后还原解压:
[up17@iZ28dns5aezZ ~]$ tar -xzvf t.tar
1.txt
2.txt
[up17@iZ28dns5aezZ ~]$ ll
total 16
-rw-rw-r-- 1 up17 up17 10240 Sep 22 21:41 1.txt
-rw-rw-r-- 1 up17 up17 0 Sep 22 21:13 2.txt
-rw-rw-r-- 1 up17 up17 146 Sep 22 21:49 t.tar
[up17@iZ28dns5aezZ ~]$
解压后还和归档压缩前大小一致。
5 和gzip 还有对应的另一种压缩bzip ,同样的tar -cvf 对应的有tar -jvf
tar -cvzf 对应的有tar -jvzf