且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

zip压缩工具、tar打包、打包并压缩

更新时间:2022-01-19 12:03:06

 zip压缩工具

可以压缩目录和文件

打包:

[root@test ~]# zip 2.txt.zip 2.txt 

  adding: 2.txt (deflated 80%)

[root@test ~]# ls

2.txt  2.txt.zip  anaconda-ks.cfg  david.txt  get-pip.py  index.php  services  test  test.tar.gz

[root@test ~]# du -sh 2.txt.zip 

4.1M2.txt.zip


压缩:

[root@test ~]# unzip 2.txt.zip -d /tmp/

Archive:  2.txt.zip

  inflating: /tmp/2.txt              

[root@test ~]# ls /tmp/2.txt 

/tmp/2.txt


查看文件名

[root@test ~]# unzip -l 2.txt.zip 

Archive:  2.txt.zip

  Length      Date    Time    Name

---------  ---------- -----   ----

 21153962  10-31-2017 10:43   2.txt

---------                     -------

 21153962                     1 file


tar打包

可以压缩目录和文件

打包目录

[root@test ~]# tar zcvf test.tar.gz  test

test/

test/test-class4.html

test/test-class1.html

test/test-class3.html

test/test-class2.html

test/test-class5.html


解压:

[root@test ~]# tar xf test.tar.gz -C /tmp/


打包时不要哪些文件--exclude 选项

[root@test ~]# tar zcvf test.tar.gz --exclude test-class4.html --exclude test-class3.html test

test/

test/test-class1.html

test/test-class2.html

test/test-class5.html


查看压缩包内容:

[root@test ~]# tar tfv test.tar.gz 

drwxr-xr-x root/root         0 2017-09-09 07:46 test/

-rw-r--r-- root/root         0 2017-09-09 07:46 test/test-class4.html

-rw-r--r-- root/root         0 2017-09-09 07:46 test/test-class3.html

-rw-r--r-- root/root         0 2017-09-09 07:46 test/test-class5.html










本文转自方向对了,就不怕路远了!51CTO博客,原文链接: http://blog.51cto.com/jacksoner/1977716,如需转载请自行联系原作者