zip压缩工具、tar打包、

一、zip压缩工具
1. zip     压缩文件,zip+[压缩后的文件名]+[需要压缩的文件]
1. [root@localhost ys]# zip 2.txt.zip 2.txt
    adding: 2.txt (deflated 75%)
2. [root@localhost ys]# du -sh 2.txt.zip
    636K    2.txt.zip

2. zip -r 压缩目录,zip压缩文件后原文件不删除
[root@localhost tmp]# zip -r qw.zip qw      压缩目录,命名为qw.zip
updating: qw/ (stored 0%)
  adding: qw/aa.txt.gz (deflated 0%)
  adding: qw/aa.txt (deflated 0%)
  adding: qw/ys/ (stored 0%)
  adding: qw/ys/2.txt (deflated 75%)
  adding: qw/ys/test.txt.xz (deflated 0%)
3. unzip  解压缩文件
[root@localhost tmp]# unzip qw.zip
Archive:  qw.zip
replace qw/aa.txt.gz? [y]es, [n]o, [A]ll, [N]one, [r]ename: y        #因为zip压缩文件后原文件不删除,那么解压缩时就会有相同的文件,
  inflating: qw/aa.txt.gz                                                                  #y就是同意覆盖,A就是全部覆盖
replace qw/aa.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
  inflating: qw/aa.txt               
  inflating: qw/ys/2.txt             
  inflating: qw/ys/test.txt.xz
4. unzip -d 指定压缩或解压缩的目录
[root@localhost tmp]# unzip qw.zip -d /ys         #解压缩qw.zip,并指定目录ys
Archive:  qw.zip
   creating: /ys/qw/
  inflating: /ys/qw/aa.txt.gz        
  inflating: /ys/qw/aa.txt           
   creating: /ys/qw/ys/
  inflating: /ys/qw/ys/2.txt         
  inflating: /ys/qw/ys/test.txt.xz
5. unzip  解压缩的时候不支持更改文件名
[root@localhost tmp]# unzip 2.txt.zip -d /ys/3.txt         #解压缩2.txt.zip,并放到ys目录下命名为3.txt
Archive:  2.txt.zip
  inflating: /ys/3.txt/2.txt                                    #可以看到把3.txt当作一个目录,把2.txt放在这个目录下
6. unzip -l  查看zip压缩文件的文件列表
[root@localhost tmp]# unzip -l qw.zip
Archive:  qw.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0         01-05-2018 17:12   qw/
   650522   01-04-2018 19:02   qw/aa.txt.gz
   650522   01-04-2018 19:01   qw/aa.txt
        0         01-05-2018 17:12   qw/ys/
  2593032  01-05-2018 17:12   qw/ys/2.txt
    49328    01-05-2018 17:12   qw/ys/test.txt.xz
---------                     -------
  3943404                     6 files

二、tar打包工具
1. tar -cvf    打包目录或文件
[root@localhost tmp]# tar -cvf ys.tar ys
ys/
ys/2.txt
ys/test.txt.xz
ys/2.txt.zip
2. tar -xvf   解包
[root@localhost tmp]# tar -xvf ys.tar
ys/
ys/2.txt
ys/test.txt.xz
ys/2.txt.zip
3. tar -tf    列出包里面的文件
[root@localhost tmp]# tar -tf ys.tar
ys/
ys/2.txt
ys/test.txt.xz
ys/2.txt.zip
4. tar -exclude   打包的时候过滤包
1. [root@localhost tmp]# tar -cvf qw.tar --exclude 333 qw ys               # 打包qw和ys的时候过滤掉333这个目录或文件
    qw/
    qw/ys/
    qw/ys/2.txt
    qw/ys/test.txt.xz
    qw/aa.txt.gz
    qw/aa.txt
    qw/123
    ys/
    ys/2.txt
    ys/test.txt.xz
    ys/2.txt.zip
2. [root@localhost tmp]# tar -cvf ss.tar --exclude "*.txt" qw ys             #同时也支持通配符,过滤所有的.txt结尾的文件
    qw/
    qw/ys/
    qw/ys/test.txt.xz
    qw/aa.txt.gz
    qw/123
    qw/333/
    ys/
    ys/test.txt.xz
    ys/2.txt.zip

三、打包压缩和解包解压缩
1. tar -czvf     打包并使用gzip进行压缩
     tar -cjvf    打包并使用bzip2进行压缩,bzip2使用的是小写的“j”
    tar -cJvf    打包并使用xz进行压缩,xz使用的是大写的“J”
[root@localhost tmp]# tar -zcvf qw.tar.gz qw ys 2.txt           #将qw ys 2.txt打包并使用gzip压缩
qw/
qw/ys/
qw/ys/2.txt
qw/ys/test.txt.xz
qw/aa.txt.gz
qw/aa.txt
qw/123
qw/333/
qw/333/nn.txt
qw/333/99.txt
ys/
ys/2.txt
ys/test.txt.xz
ys/2.txt.zip
2.txt
2. 解包并解压缩就是将c更改为x即可
    tar -xzvf       解包gzip压缩的文件
    tar -xjvf        解包bzip2压缩的文件
    tar -xJvf       解包xz压缩的文件











评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值