- 6.5 zip壓縮工具
- 6.6 tar打包
- 6.7 打包並壓縮
-
zip壓縮工具
xz,bzip2,gzip都不支持壓縮目錄
zip可以壓縮目錄
壓縮文件
zip 2.txt.zip 2.txt
[root@localhost ~]# zip 2.txt.zip 2.txt
adding: 2.txt (deflated 99%)
[root@localhost ~]# du -sh *
108K 2.txt
4.0K 2.txt.zip
壓縮目錄+文件
zip -r test.zip 2.txt test/
[root@localhost ~]# zip -r test.zip 3.txt test/
解壓文件
unzip test.zip
指定解壓到某個目錄
[root@localhost ~]# unzip 2.txt.zip -d /tmp
Archive: 2.txt.zip
inflating: /tmp/2.txt
解壓的時候,不能指定解壓后的文件名稱
如果指定了,就會先創建指定的文件名
[root@localhost ~]# unzip 2.zip -d /1.txt
Archive: 2.zip
inflating: /1.txt/2.txt
creating: /1.txt/2/
查看文件列表,但是不可以查看文件內容
unzip -l 2.zip
-
tar打包
小提示:
求實際傳輸帶寬:
1M = 8 M/s
100M / 8m/s=12.5M/s
tar打包工具
可以打包文件、目錄、文件和目錄一起,類似zip
打包:
tar -cvf xiaobo.tar xiaobo/
c create創建
v view 可視化看到過程
f 打包成的文件名
[root@localhost ~]# tar -cvf xiaobo.tar xiaobo/
xiaobo/
xiaobo/2/
xiaobo/2.txt
xiaobo/2.txt.zip
xiaobo/2.zip
xiaobo/3.txt
xiaobo/anaconda-ks.cfg
xiaobo/test.zip
[root@localhost ~]#
如果原來的tar包存在,再打包相同的文件打包名的話 就會默認覆蓋!
解包:
tar -xvf xiaobo.tar
解包后會默認覆蓋已經存在的文件
查看壓縮包里面的文件列表
tar -tf xiaobo.tar
過濾指定的文件,不去打包該文件:
不打包xiaobo目錄下的2.txt的文件
tar -cvf xiaobo.tar --exclude 2.txt xiaobo/
[root@localhost ~]# tar -cvf xiaobo.tar --exclude 2.txt xiaobo/
xiaobo/
xiaobo/2/
xiaobo/2.txt.zip
xiaobo/2.zip
xiaobo/3.txt
xiaobo/anaconda-ks.cfg
xiaobo/test.zip
[root@localhost ~]#
可以過濾多個文件:
過濾掉 txt文件類型的,過濾掉 zip文件類型的
tar -cvf xiaobo.tar --exclude "*.txt" --exclude "*.zip" xiaobo/
[root@localhost ~]# tar -cvf xiaobo.tar --exclude "*.txt" --exclude "*.zip" xiaobo/
xiaobo/
xiaobo/2/
xiaobo/anaconda-ks.cfg
[root@localhost ~]#
打包並壓縮:
支持(zip)的用 czvf
tar -czvf xiaobo.tar.gz xiaobo/
支持(bzip2)的用 j
tar -cjvf xiaobo.tar.bz2 xiaobo/
支持(xz)的用 J
tar -cJvf xiaobo.tar.xz xiaobo/
解壓:
(zip)
tar -zxvf xiaobo.tar.gz
(bzip2)
tar -jxvf xiaobo.tar.bz2
(xz)
tar -Jxvf xiaobo.tar.xz
查看壓縮包里面的文件列表
tar -tf xiaobo.tar
tar -tf xiaobo.tar.gz
tar -tf xiaobo.bz2
tar -tf xiaobo.tar.xz