码迷,mamicode.com
首页 > 其他好文 > 详细

6.25 6.5-6.7

时间:2018-06-26 11:12:15      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:txt   报错   没有   bsp   bzip   文件名   重命名   --   ted   

6.5 zip压缩工具

 

zip工具压缩的文件为.rar文件,一般linux中不使用该压缩工具

 

[root@hyc-01-01 ~]# yum install -y zip 安装zip压缩工具

[root@hyc-01-01 ~]# ls

111       222    4.txt      anaconda-ks.cfg.1  ls2       新建文本文档.txt

1.txt.xz  3.txt  4.txt.bz2  hyc2               test.txt

[root@hyc-01-01 ~]# zip 4.txt.zip 4.txt 压缩4.txt并将压缩包命名为4.txt.zip

  adding: 4.txt (deflated 75%)

[root@hyc-01-01 ~]# ls

111       222    4.txt      4.txt.zip          hyc2  test.txt

1.txt.xz  3.txt  4.txt.bz2  anaconda-ks.cfg.1  ls2   新建文本文档.txt

[root@hyc-01-01 ~]# du -sh 4.txt.zip

320K         4.txt.zip

[root@hyc-01-01 ~]# du -sh 4.txt

1.3M        4.txt

zip工具压缩的程度较小

 

压缩工具压缩程度大小不绝对,具体压缩程度与被压缩文件内容有关

 

zip支持压缩目录

[root@hyc-01-01 ~]# zip -r 111.zip 3.txt 111 将目录111和文件3.txt压缩为111.zip

[root@hyc-01-01 ~]# ls 压缩完成后原来的文件不会被删除

111       222    4.txt.bz2          hyc2      新建文本文档.txt

111.zip   3.txt  4.txt.zip          ls2

1.txt.xz  4.txt  anaconda-ks.cfg.1  test.txt

[root@hyc-01-01 ~]# yum install -y unzip 安装unzip解压工具

[root@hyc-01-01 ~]# unzip 111.zip 解压缩111.zip

Archive:  111.zip

replace 3.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A

  inflating: 3.txt                  

 extracting: 111/222/aaa            

 extracting: 111/22                 

 extracting: 111/.12.txt.swp        

 extracting: 111/.12.txt.swx        

  inflating: 111/12_txt.swp         

  inflating: 111/12.txt             

  inflating: 111/2.txt              

  inflating: 111/2.txt.t 

此处y为是,n为否,A为全部yesN为全部nr则重命名

[root@hyc-01-01 ~]# unzip 111.zip -d test 指定将111.zip解压到test目录

[root@hyc-01-01 ~]# unzip ls2.zip -d test/bb 想要指定文件位置到test目录并修改文件名为bb

Archive:  ls2.zip

 extracting: test/bb/ls2            

[root@hyc-01-01 ~]# ls test

111  3.txt  aa.txt  bb

[root@hyc-01-01 ~]# ls -l test/bb 系统在test目录下创建了bb目录并将ls2存放到了bb目录下

总用量 0

-rw-r--r--. 1 root root 0 6   5 21:17 ls2

unzip不支持修改文件名

[root@hyc-01-01 ~]# unzip -l 111.zip 查看压缩包中包含的文件

 

unzip没有类似zcatxzcat的工具,无法查看压缩文件内容

 

6.6 tar打包

 

如果不打包,则需要传输多个文件时需要一个一个传,对带宽利用率不高,耗时较长;打包后可以一次性将被打包的多个文件同时传输;

 

tar打包可能减小传输文件大小:

假如传输的每个文件均小于一个块的大小(假设4k),若分开传输10个这样的文件就需要4Kx10=40K,若打包传输则会将不足一个块大小的多个文件压到一个块上,若每个文件大小为1K,则打包传输需要传约12K大小,不打包则需要40K

 

[root@hyc-01-01 ~]# tar -cvf 111.tar 111/ 打包111目录

111/

111/222/

111/222/aaa

111/2/

111/22

111/.12.txt.swp

111/.12.txt.swx

111/12_txt.swp

111/12.txt

111/2.txt

111/2.txt.t

-:可以不加

c:创建tar

v:使创建过程可视化

f:指定tar包的包名称

[root@hyc-01-01 ~]# tar -cvf 111.tar 111/

重复执行上面的打包操作则会用新的tar包覆盖掉原来的,不报错

[root@hyc-01-01 ~]# tar -xvf 111.tar 解包

111/

111/222/

111/222/aaa

111/2/

111/22

111/.12.txt.swp

111/.12.txt.swx

111/12_txt.swp

111/12.txt

111/2.txt

111/2.txt.t

解包时没有任何提示,解包后的文件会直接覆盖目录中原来的文件

 

[root@hyc-01-01 ~]# tar -cvf 111.tar 111 ls2

111/

111/222/

111/222/aaa

111/2/

111/22

111/.12.txt.swp

111/.12.txt.swx

111/12_txt.swp

111/12.txt

111/2.txt

111/2.txt.t

ls2

tar工具可以同时打包文件和目录,也可以分开单独打包

 

[root@hyc-01-01 ~]# tar -tf 111.tar 查看打包了哪些文件

111/

111/222/

111/222/aaa

111/2/

111/22

111/.12.txt.swp

111/.12.txt.swx

111/12_txt.swp

111/12.txt

111/2.txt

111/2.txt.t

ls2

 

[root@hyc-01-01 ~]# tar -cvf test.tar --exclude bb --exclude 3.txt test ls2 只打包目录中的部分内容

test/

test/111/

test/111/222/

test/111/222/aaa

test/111/22

test/111/.12.txt.swp

test/111/.12.txt.swx

test/111/12_txt.swp

test/111/12.txt

test/111/2/

test/111/2.txt

test/111/2.txt.t

test/aa.txt/

test/aa.txt/4.txt

ls2

[root@hyc-01-01 ~]# ls test

111  3.txt  aa.txt  bb

 

[root@hyc-01-01 ~]# tar -cvf test.tar --exclude bb --exclude "*.txt" test ls2

test/

test/111/

test/111/222/

test/111/222/aaa

test/111/22

test/111/.12.txt.swp

test/111/.12.txt.swx

test/111/12_txt.swp

test/111/2/

test/111/2.txt.t

ls2

[root@hyc-01-01 ~]# tar tf test.tar

test/

test/111/

test/111/222/

test/111/222/aaa

test/111/22

test/111/.12.txt.swp

test/111/.12.txt.swx

test/111/12_txt.swp

test/111/2/

test/111/2.txt.t

ls2

过滤匹配*.txt的文件不对其执行打包操作

 

6.7 打包并压缩

 

[root@hyc-01-01 ~]# tar -zcvf 111.tar.gz 111 3.txt 4.txt

tar打包并用gzip压缩

111/

111/222/

111/222/aaa

111/2/

111/22

111/.12.txt.swp

111/.12.txt.swx

111/12_txt.swp

111/12.txt

111/2.txt

111/2.txt.t

3.txt

4.txt

[root@hyc-01-01 ~]# du -sh 111 3.txt 4.txt

1.3M        111

4.0K 3.txt

1.3M        4.txt

[root@hyc-01-01 ~]# du -sh 111.tar.gz

640K         111.tar.gz

[root@hyc-01-01 ~]# tar -jcvf 111.tar.bz2 111 3.txt 4.txt

tar打包,用bzip2压缩

[root@hyc-01-01 ~]# du -sh 111.tar.bz2

220K         111.tar.bz2

[root@hyc-01-01 ~]# tar -Jcvf 111.tar.xz 111 3.txt 4.txt

tar打包,用xz压缩

[root@hyc-01-01 ~]# du -sh 111.tar.xz

52K  111.tar.xz

 

[root@hyc-01-01 ~]# tar -Jxvf 111.tar.xz

解包并解压缩

111/

111/222/

111/222/aaa

111/2/

111/22

111/.12.txt.swp

111/.12.txt.swx

111/12_txt.swp

111/12.txt

111/2.txt

111/2.txt.t

3.txt

4.txt

 

[root@hyc-01-01 ~]# tar -tf 111.tar.gz

查看包含的文件

适用于任何压缩工具压缩的包、被打包的纯tar文件、被打包并压缩的文件(xzgzbz2等)

111/

111/222/

111/222/aaa

111/2/

111/22

111/.12.txt.swp

111/.12.txt.swx

111/12_txt.swp

111/12.txt

111/2.txt

111/2.txt.t

3.txt

4.txt


6.25 6.5-6.7

标签:txt   报错   没有   bsp   bzip   文件名   重命名   --   ted   

原文地址:http://blog.51cto.com/12216458/2132679

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!