zip命令能夠壓縮目錄和文件,-r 壓縮目錄。數組
[root@yong-02 yyl]# zip 2.txt.zip 2.txt -bash: zip: 未找到命令 [root@yong-02 yyl]# yum install -y zip
[root@yong-02 gzip]# zip 2.txt.zip 2.txt adding: 2.txt (deflated 74%) [root@yong-02 gzip]# ls 1.txt 2.txt 2.txt.zip 3.txt 4.txt 5.txt yyl [root@yong-02 gzip]# du -sh 2.txt.zip 560K 2.txt.zip
[root@yong-02 gzip]# zip -r yyl.zip yyl adding: yyl/ (stored 0%) adding: yyl/1.txt (deflated 74%) adding: yyl/2.txt (deflated 74%) adding: yyl/3.txt (deflated 74%) adding: yyl/4.txt (deflated 74%) adding: yyl/5.txt (deflated 74%) [root@yong-02 gzip]# ls 1.txt 2.txt 2.txt.zip 3.txt 4.txt 5.txt yyl yyl.zip [root@yong-02 gzip]# du -sh yyl.zip 2.8M yyl.zip [root@yong-02 gzip]# du -sh yyl 11M yyl
[root@yong-02 gzip]# unzip yyl.zip -bash: unzip: 未找到命令 [root@yong-02 gzip]# yum install unzip
[root@yong-02 gzip]# unzip yyl.zip Archive: yyl.zip replace yyl/1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y inflating: yyl/1.txt replace yyl/2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A inflating: yyl/2.txt inflating: yyl/3.txt inflating: yyl/4.txt inflating: yyl/5.txt [root@yong-02 gzip]# ls 1.txt 2.txt 2.txt.zip 3.txt 4.txt 5.txt yyl yyl.zip
1.指定解壓文件路徑bash
[root@yong-02 gzip]# unzip yyl.zip -d test/ Archive: yyl.zip creating: test/yyl/ inflating: test/yyl/1.txt inflating: test/yyl/2.txt inflating: test/yyl/3.txt inflating: test/yyl/4.txt inflating: test/yyl/5.txt [root@yong-02 gzip]# ls test/yyl/ 1.txt 2.txt 3.txt 4.txt 5.txt
2.查看壓縮文件內容列表工具
[root@yong-02 gzip]# unzip -l yyl.zip Archive: yyl.zip Length Date Time Name --------- ---------- ----- ---- 0 04-17-2018 11:30 yyl/ 2190726 04-17-2018 11:30 yyl/1.txt 2190726 04-17-2018 11:30 yyl/2.txt 2190726 04-17-2018 11:30 yyl/3.txt 2190726 04-17-2018 11:30 yyl/4.txt 2190726 04-17-2018 11:30 yyl/5.txt --------- ------- 10953630 6 files
打包目錄yylspa
[root@yong-02 gzip]# tar -cvf yyl.tar yyl/ yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
查看打包文件yyl.tar的內容code
[root@yong-02 gzip]# tar -tf yyl.tar yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
解包文件yyl.tarip
[root@yong-02 gzip]# tar -xvf yyl.tar yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
打包目錄yyl ,可是不包含文件2.txt資源
[root@yong-02 gzip]# tar -cvf yyl.tar --exclude 2.txt yyl/ yyl/ yyl/1.txt yyl/3.txt yyl/4.txt yyl/5.txt
打包並壓縮test
打包文件並使用gzip壓縮可視化
[root@yong-02 gzip]# tar -czvf yyl.tar.gz yyl/ yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
查看打包文件打包
[root@yong-02 gzip]# tar -tf yyl.tar.gz yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
解壓縮yyl.tar.gz
[root@yong-02 gzip]# tar -zxvf yyl.tar.gz yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
打包文件並使用bzip2壓縮
[root@yong-02 gzip]# tar -cjvf yyl.tar.bz2 yyl/ yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
解壓縮yyl.tar.bz2
[root@yong-02 gzip]# tar -xjvf yyl.tar.bz2 yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
打包文件並使用xz壓縮
[root@yong-02 gzip]# tar -cJvf yyl.tar.xz yyl/ yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
解壓縮yyl.tar.xz
[root@yong-02 gzip]# tar -xJvf yyl.tar.xz yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
查看打包文件
[root@yong-02 gzip]# tar -tf yyl.tar.xz yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
壓縮包大小比較:
[root@yong-02 gzip]# du -sh yyl.tar.gz yyl.tar yyl.tar.bz2 yyl.tar.xz 2.8M yyl.tar.gz 11M yyl.tar 980K yyl.tar.bz2 60K yyl.tar.xz
注意:打包後文件越小,耗時越長,佔用cpu資源越多。