17 linux常见压缩工具——zip,unzip,gzip,gunzip,bzip2,bunzip2,tar

1        zip命令:zip 包需要使用 yum 安装 yum install zip -y

语法:zip 包名.zip 要压缩的文件或者目录

选项:

-r         递归处理,要压缩的目录。

-d        从已有的压缩文件内删除指定的文件。

[root@wangweicentos home]# zip -r b-work.zip boss
  adding: 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.txt
deleting: boss/1.txt

-x        要排除的文件。

zipnote        可以查看压缩包中的文件名。

[root@wangweicentos home]# zip -r b1-work.zip boss -x boss/1.txt
  adding: 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.txt
  adding: my.txt (stored 0%)

2      unzip命令:unzip 包需要使用 yum 安装 yum install unzip -y

选项:

-d<目录>        指定文件压缩后的要储存的目录

-x<文件>        指定不要处理 .zip 压缩文件中的哪些文件

[root@wangweicentos home]# unzip -v b1-work.zip
Archive:  b1-work.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Stored        0   0% 07-29-2022 10:19 00000000  boss/
       0  Stored        0   0% 07-29-2022 10:21 00000000  boss/1.dir/
       0  Stored        0   0% 07-29-2022 10:21 00000000  boss/1.dir/a.txt
       0  Stored        0   0% 07-29-2022 10:21 00000000  boss/2.dir/
       0  Stored        0   0% 07-29-2022 10:21 00000000  boss/2.dir/b.txt
       4  Stored        4   0% 07-29-2022 10:19 5a82fd08  boss/2.txt
       4  Stored        4   0% 07-29-2022 10:19 8891cf88  boss/3.txt
       0  Stored        0   0% 07-29-2022 12:18 00000000  my.txt
--------          -------  ---                            -------
       8                8   0%                            8 files
[root@wangweicentos home]# cd /opt
[root@wangweicentos opt]# ll
total 0
[root@wangweicentos opt]# cd /home
[root@wangweicentos home]# unzip b1-work.zip -d /opt -x boss/2.txt
Archive:  b1-work.zip
   creating: /opt/boss/
   creating: /opt/boss/1.dir/
 extracting: /opt/boss/1.dir/a.txt
   creating: /opt/boss/2.dir/
 extracting: /opt/boss/2.dir/b.txt
 extracting: /opt/boss/3.txt
 extracting: /opt/my.txt
[root@wangweicentos home]# cd /opt
[root@wangweicentos opt]# ll
total 0
drwxr-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]# ll
total 4
drwxr-xr-x. 2 root root 19 Jul 29 10:21 1.dir
drwxr-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.zip
Archive:  b1-work.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Stored        0   0% 07-29-2022 10:19 00000000  boss/
       0  Stored        0   0% 07-29-2022 10:21 00000000  boss/1.dir/
       0  Stored        0   0% 07-29-2022 10:21 00000000  boss/1.dir/a.txt
       0  Stored        0   0% 07-29-2022 10:21 00000000  boss/2.dir/
       0  Stored        0   0% 07-29-2022 10:21 00000000  boss/2.dir/b.txt
       4  Stored        4   0% 07-29-2022 10:19 5a82fd08  boss/2.txt
       4  Stored        4   0% 07-29-2022 10:19 8891cf88  boss/3.txt
--------          -------  ---                            -------
       8                8   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是参数,指定解目录

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值