zip命令能夠壓縮目錄和文件,-r 壓縮目錄。linux
[root@linux-128 d6z]# zip 1.txt.zip 1.txt -bash: zip: 未找到命令 [root@linux-128 d6z]# yum install -y zip
[root@linux-128 d6z]# zip 1.txt.zip 1.txt adding: 1.txt (deflated 74%) [root@linux-128 d6z]# ls 1.txt 1.txt.zip 2.txt 3.txt 4.txt test [root@linux-128 d6z]# du -sh 1.txt.zip 664K 1.txt.zip
[root@linux-128 d6z]# zip -r test.zip test adding: test/ (stored 0%) adding: test/3.txt (deflated 74%) adding: test/4.txt (deflated 74%) [root@linux-128 d6z]# ls 1.txt 1.txt.zip 2.txt 3.txt 4.txt test test.zip [root@linux-128 d6z]# du -sh test.zip 1.3M test.zip [root@linux-128 d6z]# du -sh test 5.0M test
[root@linux-128 d6z]# unzip 1.txt.zip -bash: unzip: 未找到命令 [root@linux-128 d6z]# yum install -y unzip
[root@linux-128 d6z]# unzip 1.txt.zip Archive: 1.txt.zip replace 1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A //A表示所有 inflating: 1.txt [root@linux-128 d6z]# ls 1.txt 1.txt.zip 2.txt 3.txt 4.txt test test.zip
[root@linux-128 d6z]# unzip test.zip Archive: test.zip replace test/3.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A inflating: test/3.txt inflating: test/4.txt
[root@linux-128 d6z]# unzip test.zip -d /tmp/test Archive: test.zip creating: /tmp/test/test/ inflating: /tmp/test/test/3.txt inflating: /tmp/test/test/4.txt [root@linux-128 d6z]# ls /tmp/test 333 test test1 test2
[root@linux-128 d6z]# unzip -l test.zip Archive: test.zip Length Date Time Name --------- ---------- ----- ---- 0 11-10-2017 22:44 test/ 2572100 11-10-2017 22:43 test/3.txt 2572100 11-10-2017 22:44 test/4.txt
[root@linux-128 d6z]# tar -cvf test.tar test 1.txt 2.txt test/ test/3.txt test/4.txt 1.txt 2.txt [root@linux-128 d6z]# ls 1.txt 1.txt.zip 2.txt 3.txt 4.txt test test.tar test.zip
[root@linux-128 d6z]# tar -tf test.tar test/ test/3.txt test/4.txt 1.txt 2.txt
[root@linux-128 d6z]# tar -xvf test.tar test/ test/3.txt test/4.txt 1.txt 2.txt
[root@linux-128 d6z]# tar -cvf test.tar --exclude 3.txt test 1.txt 2.txt test/ test/4.txt 1.txt 2.txt
[root@linux-128 d6z]# tar -cvf test.tar --exclude 3.txt --exclude test 1.txt 2.txt 1.txt 2.txt
[root@linux-128 d6z]# tar -zcvf test.tar.gz test 1.txt 2.txt test/ test/3.txt test/4.txt 1.txt 2.txt [root@linux-128 d6z]# ls 1.txt 1.txt.zip 2.txt 3.txt 4.txt test test.tar test.tar.gz test.zip
[root@linux-128 d6z]# tar -tf test.tar.gz test/ test/3.txt test/4.txt 1.txt 2.txt
解包
[root@linux-128 d6z]# tar -zxvf test.tar.gz test/ test/3.txt test/4.txt 1.txt 2.txt
[root@linux-128 d6z]# tar -jcvf test.tar.bz2 test 1.txt 2.txt test/ test/3.txt test/4.txt 1.txt 2.txt
解包
[root@linux-128 d6z]# tar -jxvf test.tar.bz2 test/ test/3.txt test/4.txt 1.txt 2.txt
[root@linux-128 d6z]# tar -Jcvf test.tar.xz test 1.txt 2.txt test/ test/3.txt test/4.txt 1.txt 2.txt
解包
[root@linux-128 d6z]# tar -Jxvf test.tar.xz test/ test/3.txt test/4.txt 1.txt 2.txt
[root@linux-128 d6z]# tar tf test.tar.xz test/ test/3.txt test/4.txt 1.txt 2.txt
[root@linux-128 d6z]# du -sh test.tar.gz test.tar.bz2 test.tar.xz 2.6M test.tar.gz 988K test.tar.bz2 64K test.tar.xz
注意:打包後文件越小,耗時越長,佔用cpu資源越多。數組