1 zip命令:zip 包需要使用 yum 安装 yum install zip -y
语法:zip 包名.zip 要压缩的文件或者目录
选项:
-r 递归处理,要压缩的目录。
-d 从已有的压缩文件内删除指定的文件。
[root@wangweicentos home]# zip -r b-work.zip bossadding: boss/ (stored 0%)adding: boss/1.dir/ (stored 0%)adding: boss/1.dir/a.txt (stored 0%)adding: boss/2.dir/ (stored 0%)adding: boss/2.dir/b.txt (stored 0%)adding: boss/1.txt (stored 0%)adding: boss/2.txt (stored 0%)adding: boss/3.txt (stored 0%)[root@wangweicentos home]# zip -d b-work.zip boss/1.txtdeleting: boss/1.txt
-x 要排除的文件。
zipnote 可以查看压缩包中的文件名。
[root@wangweicentos home]# zip -r b1-work.zip boss -x boss/1.txtadding: boss/ (stored 0%)adding: boss/1.dir/ (stored 0%)adding: boss/1.dir/a.txt (stored 0%)adding: boss/2.dir/ (stored 0%)adding: boss/2.dir/b.txt (stored 0%)adding: boss/2.txt (stored 0%)adding: boss/3.txt (stored 0%)[root@wangweicentos home]# zipnote b1-work.zip@ boss/@ (comment above this line)@ boss/1.dir/@ (comment above this line)@ boss/1.dir/a.txt@ (comment above this line)@ boss/2.dir/@ (comment above this line)@ boss/2.dir/b.txt@ (comment above this line)@ boss/2.txt@ (comment above this line)@ boss/3.txt@ (comment above this line)@ (zip file comment below this line)
-m 将文件压缩并加入已经压缩好的压缩包里,删除原始文件
[root@wangweicentos home]# zip -m b1-work.zip my.txtadding: my.txt (stored 0%)
2unzip命令:unzip 包需要使用 yum 安装 yum install unzip -y
选项:
-d<目录> 指定文件压缩后的要储存的目录
-x<文件> 指定不要处理 .zip 压缩文件中的哪些文件
[root@wangweicentos home]# unzip -v b1-work.zipArchive: b1-work.zipLength Method Size Cmpr Date Time CRC-32 Name-------- ------ ------- ---- ---------- ----- -------- ----0 Stored 0 0% 07-29- 10:19 00000000 boss/0 Stored 0 0% 07-29- 10:21 00000000 boss/1.dir/0 Stored 0 0% 07-29- 10:21 00000000 boss/1.dir/a.txt0 Stored 0 0% 07-29- 10:21 00000000 boss/2.dir/0 Stored 0 0% 07-29- 10:21 00000000 boss/2.dir/b.txt4 Stored 4 0% 07-29- 10:19 5a82fd08 boss/2.txt4 Stored 4 0% 07-29- 10:19 8891cf88 boss/3.txt0 Stored 0 0% 07-29- 12:18 00000000 my.txt--------------- --- -------88 0% 8 files[root@wangweicentos home]# cd /opt[root@wangweicentos opt]# lltotal 0[root@wangweicentos opt]# cd /home[root@wangweicentos home]# unzip b1-work.zip -d /opt -x boss/2.txtArchive: b1-work.zipcreating: /opt/boss/creating: /opt/boss/1.dir/extracting: /opt/boss/1.dir/a.txtcreating: /opt/boss/2.dir/extracting: /opt/boss/2.dir/b.txtextracting: /opt/boss/3.txtextracting: /opt/my.txt[root@wangweicentos home]# cd /opt[root@wangweicentos opt]# lltotal 0drwxr-xr-x. 4 root root 45 Jul 29 10:19 boss-rw-r--r--. 1 root root 0 Jul 29 12:18 my.txt[root@wangweicentos opt]# cd boss[root@wangweicentos boss]# lltotal 4drwxr-xr-x. 2 root root 19 Jul 29 10:21 1.dirdrwxr-xr-x. 2 root root 19 Jul 29 10:21 2.dir-rw-r--r--. 1 root root 4 Jul 29 10:19 3.txt
-v查看压缩文件夹下的目录但是不解压
[root@wangweicentos home]# unzip -v b1-work.zipArchive: b1-work.zipLength Method Size Cmpr Date Time CRC-32 Name-------- ------ ------- ---- ---------- ----- -------- ----0 Stored 0 0% 07-29- 10:19 00000000 boss/0 Stored 0 0% 07-29- 10:21 00000000 boss/1.dir/0 Stored 0 0% 07-29- 10:21 00000000 boss/1.dir/a.txt0 Stored 0 0% 07-29- 10:21 00000000 boss/2.dir/0 Stored 0 0% 07-29- 10:21 00000000 boss/2.dir/b.txt4 Stored 4 0% 07-29- 10:19 5a82fd08 boss/2.txt4 Stored 4 0% 07-29- 10:19 8891cf88 boss/3.txt--------------- --- -------88 0% 7 files
-o 不必先询问用户,unzip执行后覆盖原有文件。
3 gzip :gunzip命令用来压缩文件
gzip选项:只能将文件压缩为 *.gz 文件
-l 列出文件的相关信息,并不解压
-rv 递归的压缩目录
缺陷:不保留原文件
gunzip选项:
-dr 递归的解压目录
缺陷:解压时只能解压到当前目录下
4 bzip2,bunzip2
选项:
-f bzip2在压缩或者解压缩时,若输出文件与现有文件同名,预设不会覆盖现有文件。若需要,则使用此选项
-k bzip2 在压缩或解压缩后,会删除原始文件。若要保留原始文件,则使用此参数。
-z 强制执行压缩
5 tar 打包归档指令
压缩文件:先将文件打成一个包(tar命令),然后再用压缩程序进行压缩(gzip bzip2命令)。
选项(必须):
-c 产生 .tar 打包文件
-x 解包 .tar 文件
-v 显示详细信息
-f 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名。
(根据要求选择):
-z 有gzip属性的
-j 有bz2属性的
案例:将myhome.tar.gz 解压到 /opt/tmp2 目录下
tar -zxvf /home/home.tar.gz -C /opt/tmp2
注意:大C是参数,指定解目录