【2018.04.17学习笔记】【linux基础知识6.5-6.7】

6.5 zip压缩工具

zip命令:压缩后原文件不被删除,可以支持压缩目录。

[root@lgs-01 ~]# zip abc.zip abc
  adding: abc (deflated 65%)
[root@lgs-01 ~]# ls -l abc
-rwxr-xr-x. 1 root root 3073568 4月  16 18:00 abc
[root@lgs-01 ~]# ls -l abc.zip 
-rw-r--r--. 1 root root 1090963 4月  17 23:18 abc.zip
[root@lgs-01 ~]# du -sh abc.zip 
1.1M	abc.zip

压缩目录:-r选项

[root@lgs-01 ~]# zip -r 123.zip ./c/ abc
  adding: c/ (stored 0%)
  adding: c/x/ (stored 0%)
  adding: c/y/ (stored 0%)
  adding: c/6.txt.bak (stored 0%)
  adding: c/4.txt.bak (stored 0%)
  adding: c/3.txt.bak (stored 0%)
  adding: c/10.txt.bak (stored 0%)
  adding: c/11.txt.bak (deflated 98%)
  adding: c/666.gz (stored 0%)
  adding: c/abc1.bz2 (deflated 0%)
  adding: c/abc1.xz (deflated 0%)
  adding: abc (deflated 65%)
[root@lgs-01 ~]# du -sh 123.zip 
2.9M	123.zip

解压缩: unzip

[root@lgs-01 ~]# unzip 123.zip
Archive:  123.zip
replace c/6.txt.bak? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
 extracting: c/6.txt.bak             
 extracting: c/4.txt.bak             
 extracting: c/3.txt.bak             
 extracting: c/10.txt.bak            
  inflating: c/11.txt.bak            
 extracting: c/666.gz                
  inflating: c/abc1.bz2              
  inflating: c/abc1.xz               
  inflating: abc 

指定解压到哪个目录:-d

[root@lgs-01 ~]# unzip 123.zip -d ./b/
Archive:  123.zip
   creating: ./b/c/
   creating: ./b/c/x/
   creating: ./b/c/y/
 extracting: ./b/c/6.txt.bak         
 extracting: ./b/c/4.txt.bak         
 extracting: ./b/c/3.txt.bak         
 extracting: ./b/c/10.txt.bak        
  inflating: ./b/c/11.txt.bak        
 extracting: ./b/c/666.gz            
  inflating: ./b/c/abc1.bz2          
  inflating: ./b/c/abc1.xz           
  inflating: ./b/abc                 
[root@lgs-01 ~]# ls -l ./b/
总用量 3004
-rwxr-xr-x. 1 root root 3073568 4月  16 18:00 abc
drwxr-xr-x. 4 root root     156 4月  17 23:28 c

查看zip压缩文件的文件列表,不能查看文件内容:unzip -l

[root@lgs-01 ~]# unzip -l 123.zip 
Archive:  123.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  04-17-2018 23:28   c/
        0  03-30-2018 12:33   c/x/
        0  03-30-2018 12:39   c/y/
        0  03-28-2018 16:36   c/6.txt.bak
        0  03-28-2018 16:40   c/4.txt.bak
        0  03-30-2018 12:33   c/3.txt.bak
        0  03-30-2018 12:39   c/10.txt.bak
     8294  04-01-2018 21:56   c/11.txt.bak
     1656  04-16-2018 18:15   c/666.gz
  1078029  04-16-2018 18:27   c/abc1.bz2
   831676  04-16-2018 18:35   c/abc1.xz
  3073568  04-16-2018 18:00   abc
---------                     -------
  4993223                     12 files

6.6 tar打包

tar:打包命令,对文件大小变化不大。

[root@lgs-01 ~]# tar -cvf abc.tar ./c
./c/
./c/x/
./c/y/
./c/6.txt.bak
./c/4.txt.bak
./c/3.txt.bak
./c/10.txt.bak
./c/11.txt.bak
./c/666.gz
./c/abc1.bz2
./c/abc1.xz
[root@lgs-01 ~]# du -sh ./c
1.9M	./c
[root@lgs-01 ~]# du -sh abc.tar 
1.9M	abc.tar

目录和文件一起打包:

[root@lgs-01 ~]# tar -cvf 333.tar b/ abc zb.txt
b/
b/c/
b/c/x/
b/c/y/
b/c/6.txt.bak
b/c/4.txt.bak
b/c/3.txt.bak
b/c/10.txt.bak
b/c/11.txt.bak
b/c/666.gz
b/c/abc1.bz2
b/c/abc1.xz
b/abc
abc
zb.txt
[root@lgs-01 ~]# du -sh 333.tar 
7.8M	333.tar

解包:-xvf。会覆盖原文件和目录,不会提示

[root@lgs-01 ~]# tar -xvf 333.tar 
b/
b/c/
b/c/x/
b/c/y/
b/c/6.txt.bak
b/c/4.txt.bak
b/c/3.txt.bak
b/c/10.txt.bak
b/c/11.txt.bak
b/c/666.gz
b/c/abc1.bz2
b/c/abc1.xz
b/abc
abc
zb.txt

查看包文件列表:-tf

[root@lgs-01 ~]# tar -tf 333.tar 
b/
b/c/
b/c/x/
b/c/y/
b/c/6.txt.bak
b/c/4.txt.bak
b/c/3.txt.bak
b/c/10.txt.bak
b/c/11.txt.bak
b/c/666.gz
b/c/abc1.bz2
b/c/abc1.xz
b/abc
abc
zb.txt

排除文件打包:--exclude

[root@lgs-01 ~]# tar -cvf 888.tar b/ abc c/ --exclude "*.bak"
b/
b/c/
b/c/x/
b/c/y/
b/c/666.gz
b/c/abc1.bz2
b/c/abc1.xz
b/abc
abc
c/
c/x/
c/y/
c/666.gz
c/abc1.bz2
c/abc1.xz

6.7 打包并压缩

tar -czvf:打包并压缩成gz。 -xzvf 解压

[root@lgs-01 ~]# tar -czvf 9.tar.gz abc zb.txt b/
abc
zb.txt
b/
b/c/
b/c/x/
b/c/y/
b/c/6.txt.bak
b/c/4.txt.bak
b/c/3.txt.bak
b/c/10.txt.bak
b/c/11.txt.bak
b/c/666.gz
b/c/abc1.bz2
b/c/abc1.xz
b/abc
[root@lgs-01 ~]# du -sh 9.tar.gz 
4.0M	9.tar.gz

tar -cjvf:打包并压缩成bz2。 -jzvf 解压

[root@lgs-01 ~]# tar cjvf 7.tar.bz2 c/ xxx.conf.xz 123.zip 
c/
c/x/
c/y/
c/6.txt.bak
c/4.txt.bak
c/3.txt.bak
c/10.txt.bak
c/11.txt.bak
c/666.gz
c/abc1.bz2
c/abc1.xz
xxx.conf.xz
123.zip
[root@lgs-01 ~]# du -sh 7.tar.bz2 
4.8M	7.tar.bz2

tar -cJvf:打包并压缩成xz。 -Jzvf 解压

[root@lgs-01 ~]# tar -cJvf 5.tar.xz c/ abc b/ passwdtest 
c/
c/x/
c/y/
c/6.txt.bak
c/4.txt.bak
c/3.txt.bak
c/10.txt.bak
c/11.txt.bak
c/666.gz
c/abc1.bz2
c/abc1.xz
abc
b/
b/c/
b/c/x/
b/c/y/
b/c/6.txt.bak
b/c/4.txt.bak
b/c/3.txt.bak
b/c/10.txt.bak
b/c/11.txt.bak
b/c/666.gz
b/c/abc1.bz2
b/c/abc1.xz
b/abc
passwdtest
[root@lgs-01 ~]# du -sh 5.tar.xz 
2.6M	5.tar.xz

查看文件列表:tar -tf

[root@lgs-01 ~]# tar -tf 7.tar.bz2 
c/
c/x/
c/y/
c/6.txt.bak
c/4.txt.bak
c/3.txt.bak
c/10.txt.bak
c/11.txt.bak
c/666.gz
c/abc1.bz2
c/abc1.xz
xxx.conf.xz
123.zip

转载于:https://my.oschina.net/u/3804114/blog/1797042

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值