zip
好处:方便和 windows 平台交互使用
特点:可以压缩文件与目录,压缩后源文件不删除
工具安装:yum install -y zip unzip
用法 | 命令 | 实例 |
---|---|---|
压缩 | zip 【目标包名】【文件和目录】 | zip -r 1.zip 1.txt test/ |
解压缩 | unzip 【压缩包名】 | unzip 1.zip |
指定解压缩目录 | unzip 【压缩包名】 | unzip 1.zip -d /root/test |
查看压缩包 | unzip -l file 只能看文件列表不能看具体内容 | unzip -l aming.zip |
实例操作:
[root@centos701 d6z]#zip -r aming.zip 1.txt 2.txt vmware-tools-distrib/[root@centos701 d6z]# du -sh 1.txt 2.txt vmware-tools-distrib/ aming.zip1.3M 1.txt1.3M 2.txt163M vmware-tools-distrib/55M aming.zip [root@centos701 d6z]unzip -l aming.zip10144 11-12-2017 00:15 vmware-tools-distrib/vgauth/schemas/xmldsig-core-schema.xsd 1215 11-12-2017 00:15 vmware-tools-distrib/vgauth/schemas/XMLSchema-instance.xsd 8768 11-12-2017 00:15 vmware-tools-distrib/vgauth/schemas/xml.xsd 13160 11-12-2017 00:15 vmware-tools-distrib/vgauth/schemas/saml-schema-assertion-2.0.xsd 16072 11-12-2017 00:15 vmware-tools-distrib/vgauth/schemas/XMLSchema.dtd 5783 11-12-2017 00:15 vmware-tools-distrib/vgauth/schemas/XMLSchema-hasFacetAndProperty.xsd 6356 11-12-2017 00:15 vmware-tools-distrib/vgauth/schemas/datatypes.dtd 216748 11-12-2017 00:15 vmware-tools-distrib/vmware-install.pl 149442 11-12-2017 00:15 vmware-tools-distrib/FILES 2538 11-12-2017 00:15 vmware-tools-distrib/INSTALL --------- -------169410060 2080 files [root@centos701 d6z]unzip aming.zip -d /tmp/test/ [root@centos701 d6z]# du -sh /tmp/test/1.txt 2.txt vmware-tools-distrib/1.3M /tmp/test/1.txt1.3M 2.txt163M vmware-tools-distrib/
tar_打包工具
用途:将多个文件或者目录,组合在一起,有利于提高磁盘块的利用率,方便传输。但文件大小并无太大变化
以下用法都是在当前位置进行,如要跨文件夹打包,需要详细查看用法
用法 | 命令 | 参数说明 | 实例 |
---|---|---|---|
打包 | tar -cvf 【目标包名】【成员】 | -c创建 -v 可视化 -f:后面跟 tar 包名 不可省略 | tar -cvf aming.tar aming1 1.txt 2.txt |
过滤打包 | tar -cvf 【目标包名】【成员】--exclude 【成员中需要排除的文件或目录】 | 将成员中的 txt 文件和 aming1目录排除,如有多个需要排除的需多次输入--exclude | tar -cvf aming.tar aming --exclude "*.txt" --exclude aming1/ |
解包 | tar -xvf 【源包名】 | 无论是打包还是解包,都会覆盖已存在文件,没有提示,操作前请做好对应备份 | tar -xvf aming.tar |
查看包内容 | tar -tf 【源包名】 | tar -tf aming.tar |
打包并压缩
在 tar 包的参数中加入对应的参数,以实现打包的同时调用压缩工具对tar包进行压缩,压缩比率取决于工具自身
gzip < bzip2 < xz
各工具对比用法见下表:
压缩工具 | 关键参数 | 命令用法实例 |
---|---|---|
gzip | z | tar -zcvf 12.tar.gz 123 组包压缩 |
tar -zxvf 12.tar.gz 解包解压缩 | ||
bzip2 | j | tar -jcvf 12.tar.bz2 123 组包压缩 |
tar -jxvf 12.tar.bz2 解包解压缩 | ||
xz | J | tar -Jcvf 12.tar.xz 组包压缩 |
tar -Jxvf 12.tar.xz 解包解压缩 | ||
查看 | -tf | tar -tf 12.tar.gz/bz2/xz |
提示: 如果在拿到一些压缩的 tar 包无法解包的时候,请确定系统有对应的压缩工具