当前位置: 首页 > Linux

每天学一个Linux命令(41):zip

时间:2023-04-06 02:46:25 Linux

命令介绍zip命令可以用来对文件进行压缩打包。#Debian/Ubuntuinstallapt-getinstallzip#CentOSinstall[root@centos7testdir]#zip-bash:zip:commandnotfound[root@centos7testdir]#yuminstallzip-yzip命令也可以用来解压文件,Zip也是一种常用的压缩和解压缩应用程序。文件被它压缩后,会生成一个新的压缩包文件,扩展名为.zip。语法格式zip[OPTIONS][NAME..]选项说明-A#调整可执行的自动解压文件-b<工作目录>#指定压缩文件的存放目录-c#为每个压缩文件添加注释信息-d#从压缩文件中删除指定文件,或者使用--delete参数-D#不要在压缩文件中创建目录名-f#更新现有文件,将其他文件添加到压缩文件中-F#修复损坏的压缩文件-g#将指定文件压缩成已有的压缩文件,不新建文件-h#打印帮助信息-i#只压缩符合指定条件的文件-m#指定文件压缩后会直接删除原文件andpackaged-o#更改压缩文件的属性信息,使其与压缩文件中最新文件的属性信息一致-q#安静模式-r#递归处理-t<日期时间>#压缩压缩文件Set日期到指定日期-T#检查备份文件中的每个文件是否正确-u#将较新的文件更新到压缩文件中-v#打印命令执行过程信息或版本信息-x<模板样式>#排除符合条件的文件whencompressing-z#给压缩文件添加注释信息-<压缩效率>#指定压缩效率(1~9个数字)应用实例在当前目录下创建压缩文件(自动创建带.zip的文件)[root@centos7testdir]#zipmingongge*添加:cest.txt.gz(存储0%)添加:cuttest.txt.gz(存储0%)添加:dir/(存储0%)添加:文件(存储0%)添加:mingongge1.txt。gz(存储0%)添加:mingongge2.txt.gz(存储0%)添加:mingongge.txt.md5.gz(存储0%)添加:sort.cut.txt.gz(存储0%)分割一个大文件[root@centos7~]#ls-lhtotal22M-rw------.1rootroot1.3KAug2010:39anaconda-ks.cfg-rw-r--r--1rootroot140Jan1611:36dos_test.txtdrwxr-xr-x3rootroot398月3003:48goinception-rw-r--r--1rootroot13M8月3003:42goInception-linux-amd64-v1.2.3.tar.gzdrwxr-sr-x11root404.0KDec2422:35httpd-2.4.46-rw-r--r--1rootroot9.0MAug507:32httpd-2.4.46.tar.gz-rw-r--r--1rootroot0Jan1611:32mingongge.filedrwxr-xr-x3rootroot192Jan1616:19testdir-rw-r--r--1rootroot140Jan1611:32test.txt[root@centos7~]#zip-s4M-rmingongge.ziphttpd-2.4.46.tar.gz添加:httpd-2.4.46.tar.gz(压缩0%)[root@centos7~]#ls-lhtotal31M-rw------。1rootroot1.3KAug2010:39anaconda-ks.cfg-rw-r--r--1rootroot140Jan1611:36dos_test.txtdrwxr-xr-x3rootroot39Aug3003:48goinception-rw-r--r--1rootroot13MAug3003:42goInception-linux-amd64-v1.2.3.tar.gzdrwxr-sr-x11root404.0KDec2422:35httpd-2.4.46-rw-r--r--1rootroot9.0MAug507:32httpd-2.4.46.tar.gz-rw-r--r--1rootroot0Jan1611:32mingongge.file-rw-r--r--1rootroot4.0MJan1616:24mingongge.z01-rw-r--r--1rootroot4.0MJan1616:24mingongge.z02-rw-r--r--1rootroot943KJan1616:24mingongge.zipdrwxr-xr-x3rootroot192Jan1616:19testdir#from结果可以看到会被拆分成三个文件:4M大小的mingongge.z01、4M大小的mingongge.z02和一个943k的mingongge.zip文件。每天学一个Linux命令(39):tar每天学一个Linux命令(40):gzip