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

  • 6.5 zip压缩工具
  • 6.6 tar打包
  • 6.7 打包并压缩

 

  •  zip压缩工具

 

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

 

 

 

 

 

  •  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

相关文章
相关标签/搜索