xz,bzip2,gzip都不支持壓縮目錄工具
zip能夠壓縮目錄blog
壓縮文件ip
zip 2.txt.zip 2.txttest
[root@localhost ~]# zip 2.txt.zip 2.txt 可視化
adding: 2.txt (deflated 99%)打包
[root@localhost ~]# du -sh *im
108K 2.txtimg
4.0K 2.txt.zipdi
壓縮目錄+文件gzip
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
小提示:
求實際傳輸帶寬:
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