day20: zip压缩工具及打包工具介绍
2019独角兽企业重金招聘Python工程师标准>>>
1、zip:压缩工具:
相比与之前的三种工具,可用于压缩目录,在windows里和linux中比较常用:
解压缩使用格式:(压缩目录时要加“ -r ”)
zip filename.zip filename #压缩文件,压缩的文件名称要写在前面,可自定义:
unzip filename.zip #解压文件,当目标文件存在,会提示是否覆盖:
zip -r dir.zip dir filename #压缩目录,也可以同时并压缩文件:
[root@localhost d6z]# zip 1.txt.zip 1.txt #用zip格式压缩文件1.txt:adding: 1.txt (deflated 73%)
[root@localhost d6z]# du -sh 1.txt.zip #查看其文件大小:
976K 1.txt.zip
[root@localhost d6z]# unzip 1.txt.zip #用unzip解压文件:
Archive: 1.txt.zip
replace 1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A #当目标文件存在时,则会提示是否覆盖:
#yes:当压缩文件里存在多个文件时,每个文件都会询问,是否要覆盖?:
#no :当压缩文件里存在多个文件时,每个文件会询问是否不覆盖?:
#all: 当压缩文件里存在多个文件时,只询问一次,直接覆盖:
#None:直接退出,不进行当次操作:
#rename: 等于要重新新建一个文件,也是每个文件都会询问:inflating: 1.txt
[root@localhost d6z]# zip -r test.zip test 1.txt 2.txt 3.txt 4.txt #压缩目录test和压缩文件1txt.2txt..adding: test/ (stored 0%)adding: test/2.txt (deflated 73%)adding: 1.txt (stored 0%)adding: 2.txt (deflated 73%)adding: 3.txt (deflated 73%)adding: 4.txt (deflated 73%)
[root@localhost d6z]# du -sh test.zip #查看其压缩后文件大小:
3.9M test.zip
[root@localhost d6z]# ls #发现压缩或解压缩后源文件都不会删除:
1.txt 1.txt.zip 2.txt 3.txt 4.txt 5.txt test test.zip
如上图所示:压缩目录是要加“ -r ”选项:
压缩或解压缩源文件都不会删除:
2、zip压缩也支持压缩到指定目录:则需要加“ -d ”选项:
unzip filename.zip -d /test/ #压缩到指定目录: -d 后跟目录:
[root@localhost d6z]# unzip 1.txt.zip -d test #把1.txt.zip压缩到test目录下:
Archive: 1.txt.zipinflating: test/1.txt
[root@localhost d6z]# ls test #查看其文件:
1.txt 2.txt
另外zip压缩到指定目录时,不支持自定义名称,也就是说压缩前后的文件名称必须一致:
[root@localhost d6z]# unzip 1.txt.zip -d test/3.txt #解压1.txt.zip到指定目录,并自定义名称,不允许的:
Archive: 1.txt.zip inflating: test/3.txt/1.txt
[root@localhost d6z]# tree test #查看时发现自动的变成了目录,并在目录下生成了文件:
test
└── 3.txt└── 1.txt1 directory, 1 file
如上图所示:发现指定的文件名变成了目录,并把文件解压到了目录下:不可以的:
3、zip不支持查看文件内容:但支持查看文件列表:用“ -l ” 选项:
[root@localhost d6z]# zip -r test.zip test 1.txt 2.txt 3.txt #压缩目录和文件:adding: test/ (stored 0adding: test/3.txt/ (stored 0%)adding: test/3.txt/1.txt (deflated 73%)adding: 1.txt (deflated 73%)adding: 2.txt (deflated 73%)adding: 3.txt (deflated 73%)
[root@localhost d6z]# unzip -l test.zip #查看压缩的文件列表:6个文件:
Archive: test.zipLength Date Time Name
--------- ---------- ----- ----0 06-28-2018 01:01 test/0 06-28-2018 01:01 test/3.txt/3699067 06-28-2018 00:57 test/3.txt/1.txt3699067 06-28-2018 00:57 1.txt3699067 06-28-2018 00:41 2.txt3699067 06-28-2018 00:41 3.txt
--------- -------14796268 6 files
2:tar打包工具介绍:
tar打包:把目录打包成一个文件,把所有文件打包成一个大文件:
方便复制和移动:
节约带宽,方便传输:
tar打包格式:( -f后面要跟打包后的名称 )
tar -cfv dir.tar dir #对目录打包:
tar -cvf dir.tar dir filename #支持同时对目录及文件一起打包:
tar -xvf dir.tar #对目标进行解包操作:
[root@localhost d6z]# tar -cvf test.tar test #tar命令对目录test进行打包:
test/
test/3.txt/
test/3.txt/1.txt
[root@localhost d6z]# ls #查看时发现打包后不删除源文件:
1.txt 2.txt 4.txt test test.zip
1.txt.zip 3.txt 5.txt test.tar
[root@localhost d6z]# tar -xvf test.tar #tar解包test.tar:
test/
test/3.txt/
test/3.txt/1.txt
[root@localhost d6z]# tar -cvf test.tar test 1.txt 2.txt 3.txt #tar同时对目录及多个文件打包:
test/
test/3.txt/
test/3.txt/1.txt
1.txt
2.txt
3.txt
[root@localhost d6z]# tar -cf test.tar test 1.txt 2.txt 3.txt #不加” -v “选项,则不查看执行过程:并且再次打包时会覆盖,不会任何提示:
如上得知:
不加 " -v " 选项,则表示不可视化:不查看执行过程:
打包或解包时,都不会删除源文件:
打包或解包时会覆盖,不会有任何提示:
2.1:tar命令也只支持查看文件列表(同zip相同),不能查看文件内容:
tar -tf filename.tar #查看文件列表:
[root@localhost d6z]# tar -tf test.tar #用tar查看文件列表:
test/
test/3.txt/
test/3.txt/1.txt
1.txt
2.txt
3.txt
2.2:tar还支持文件过滤(不打包它): --exelude
tar -cvf dir.tar --exclude 1.txt dir 2.txt 3.txt 4.txt
#表示打包dir目录和文件,并过滤到dir目录下的1.txt文件:
[root@localhost d6z]# tar -cvf test.tar --exclude 1.txt test 2.txt 4.txt #过滤掉1.txt文件:
test/
test/11.txt
test/100.txt
2.txt
4.txt
[root@localhost d6z]# tar -tf test.tar #查看到过滤了test目录下的1.txt文件:
test/
test/11.txt
test/100.txt
2.txt
4.txt
如图所示:对当前目录test和文件2.txt 4.txt进行压缩,并过滤掉test下的1.txt:
当然:exelude也支持通配符,也支持过滤过个选项:
tar -cvf test.tar --exclude 1.txt --exclde 2.txt test 3.txt 4.txt
2.3:打包同时并压缩文件:
格式: tar [ -zjJxcvfpP ] filename.tar filename dir
常用选项如下:
-c : 表示建立一个tar包或压缩包:
-x : 表示解包或解压缩 :
-v : 表示可视化,可查看其执行过程:
-f : 后面要跟文件名(解压缩都一样的):
-t : 表示查看tar包里的文件列表:
--exclude : 表示过滤文件时使用:(打包或解压缩时使用)
-z : 表示同时用gzip格式进行压缩:
-j : 表示同时用bzip2格式进行压缩:
-J : 表示同时用xz格式进行压缩:
-p : 表示保留使用源文件的属性,压缩前后的属性一样:(不常用)
-P : 表示可以使用绝对路径:(不常用)
2.4:打包并使用gzip格式进行压缩:
tar -zcvf text.tar.gz test 1.txt 2.txt #打包并用gzip压缩,同时压目录及文件:
tar -zxvf text.tar.gz #进行解包:
[root@localhost d6z]# tar -zcvf test.tar.gz test 1.txt 2.txt #对test目录及文件打包并zip压缩:
[root@localhost d6z]# tar -tf test.tar.gz #用 “ -tf ”命令查看文件:
test/
test/11.txt
test/1.txt
test/100.txt
1.txt
2.txt
[root@localhost d6z]# tar -zxvf test.tar.gz #解包及解压缩:
test/
test/11.txt
test/1.txt
test/100.txt
1.txt
2.txt
打包并使用bzip格式进行压缩:
tar -jcvf test.tar.bz2 test 1.txt #tar打包并使用bzip压缩:
tar -jxvf test.tar.bz2 #解包解压缩:
[root@localhost d6z]# tar -jcvf test.tar.bz2 test 1.txt #打包并用bzip2格式进行压缩:
[root@localhost d6z]# tar -tf test.tar.bz2 #用 ” -tf " 查看文件列表:
test/
test/11.txt
test/1.txt
test/100.txt
1.txt
[root@localhost d6z]# tar -jxvf test.tar.bz2 #解包及解压缩:
test/
test/11.txt
test/1.txt
test/100.txt
1.txt
打包并使用xz格式压缩:
tar -Jcvf test.tar.xz test 1.txt #打包并使用xz格式进行压缩:
tar -Jxvf test.tar.xz #解包解压缩:
[root@localhost d6z]# tar -Jcvf test.tar.xz test 1.txt #打包并使用xz格式进行压缩:
[root@localhost d6z]# tar -tf test.tar.xz test 1.txt #用 ” -tf " 查看文件内容:
test/
test/11.txt
test/1.txt
test/100.txt
1.txt
[root@localhost d6z]# tar -Jxvf test.tar.xz #解包及解压缩:
test/
test/11.txt
test/1.txt
test/100.txt
1.txt
总之,用gzip bzip2 xz打包并压缩,都可以使用“ -tf ”命令进行查看文件列表,均不支持查看文件内容:
tar -ft filename.tar.gz(bzip2 xz)
转载于:https://my.oschina.net/yuanhaohao/blog/1836752
day20: zip压缩工具及打包工具介绍相关推荐
- 几个常见的Android多渠道打包工具介绍
Android项目开发完,多途径打包是必不可少的环节.其原理在于,通过在Android安卓包中增加不同的标识,区别各个途径下载来源,用于计算App在不同使用市场或途径合作中的各项数据. 工欲善其事,必 ...
- APK文件简介 及 解包 打包 工具 介绍
1. APK文件简介 APK是Android Package的缩写,即Android application package文件或Android安装包.每个要安装到Android平台的应用都要被编译打 ...
- zip压缩工具与tar打包并压缩工具
zip压缩工具 tar打包工具 tar打包并压缩 转载于:https://blog.51cto.com/13515599/2058077
- img解包工具_3、Linux基础命令篇、压缩打包工具
在管理系统中,我们遇到经常会使用后缀为*.tar.gz |*.tar.bz2 等文件,他们是什么文件呢?请看下面介绍及使用方法 压缩的原理,比如一个字符串"www.baidu.com&quo ...
- 6.5 zip压缩工具;6.6 tar打包;6.7 打包并压缩
6.5 zip压缩工具 yum安装zip压缩工具: [root@hao-01 ~]# yum install -y zip 1. zip压缩文件:zip 压缩文件名 原文件 [root@hao-01 ...
- Linux centosVMware zip压缩工具、tar打包、打包并压缩
一. zip压缩工具 可以用来压缩文件和目录,压缩目录是需要指定目录下的文件. [root@davery tmp]# cp 1.txt davery/ [root@davery tmp]# du -s ...
- gzip,bzip2压缩工具及tar打包工具
gzip,bzip2压缩工具及tar打包工具 1.gzip压缩工具 1>参数: -c:将参数的数据输出到屏幕上,可通过数据流重定向来处理 ...
- 四周第五次课(1月6日) 6.5 zip压缩工具 6.6 tar打包 6.7 打包并压缩
四周第五次课(1月6日) 6.5 zip压缩工具 6.6 tar打包 6.7 打包并压缩 tar命令: 可以为linux的文件和目录创建档案.利用tar,可以为某一特定文件创建档案(备份文件),也可以 ...
- 下一代前端打包工具-Parcel介绍
Parcel的特性 快速打包 - 多核编译,以及文件系统缓存,即使在重新启动之后也能快速重新构建. 支持JS,CSS,HTML,文件资源等- 不需要安装任何插件. 在需要的时候自动使用Babel,Po ...
- linux系统打包工具,Linux 压缩、解压缩和打包工具
前言:你是否曾经因为某个文件占用空间较大,而空间紧缺的U盘无法存放此文件.你是否曾经因为软件里有太多文件而不方便复制和携带.你是否曾因需要备份太过零散而头疼.那么基于"文件压缩和打包&quo ...
最新文章
- docker与git实现push-to-deploy
- Java自动驾驶:汽车检测
- Javascript+PHP实现在线拍照功能 (转)
- 代码对比工具,我就用这 6 个!
- 微信小程序- 初试小程序之tabbar(选项卡,底部导航)的使用
- HDFS常用的Api
- 佰腾科技:专利大数据的云上裂变之路
- mysql 修改表 引擎,mysql如何修改表类型(表引擎)
- 信访问题归并处理_最高法判例:行政机关以信访形式处理履行法定职责问题的起诉期限...
- hadoop源码学习(-)
- 什么是串口协议转换器?串口转换器有哪些特点?
- linux redis-trib.rb,redis集群配置 执行 redis-trib.rb 报错解决方法
- 高数——零点定理、介值定理的应用
- __kindof用法
- 北航计算机学院好气派,2017年北京航空航天大学国内排名第几
- [BZOJ1061][NOI2008]志愿者招募(费用流神题单纯形裸题)
- c语言实参和形参占用存储单元_c语言的形参是否占存储单元
- PS教程:磨砂颗粒质感字体海报设计
- 云班课作业互评(python3+selenium)
- [OHIF-Viewers]医疗数字阅片-医学影像-Cornerstone Tools