zip、tar工具的介绍及用法

6.5 zip压缩工具

6.6 tar打包

6.7 打包并压缩



6.5 zip压缩工具

  • 直接压缩 格式 zip 1.txt.zip 1.txt //可以看到zip需要先命名文件
[[email protected] tmp]# ls -lh 1.txt    查看文件大小
-rw-r--r--. 1 root root 3.6M 11月 10 21:44 1.txt
[[email protected] tmp]# zip 1.txt.zip 1.txt    执行zip命令压缩
  adding: 1.txt (deflated 75%)
[[email protected] tmp]# ls -lh 1.txt.zip
-rw-r--r--. 1 root root 906K 11月 10 21:45 1.txt.zip    压缩容量变小
  • 压缩目录 需要带 -r选项
[[email protected] tmp]# zip -r 123.zip 123/
  adding: 123/ (stored 0%)
  adding: 123/1.txt (deflated 75%)
[[email protected] tmp]# ls -lh 123
总用量 3.6M
-rw-r--r--. 1 root root 3.6M 11月 10 21:55 1.txt
[[email protected] tmp]# ls -lh 123.zip
-rw-r--r--. 1 root root 906K 11月 10 21:55 123.zip
  • 解压文件

[[email protected] tmp]# unzip 1.txt.zip     
Archive:  1.txt.zip
replace 1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y    询问是否覆盖,由于不删除源文件
  inflating: 1.txt                                       #解压会有提示
  • 解压目录
[[email protected] tmp]# unzip 123.zip -d /tmp/123/456/    解压目录 加 -d 选项 可以创建目录
Archive:  123.zip                                                        #或 指定目录
   creating: /tmp/123/456/123/
  inflating: /tmp/123/456/123/1.txt
  • 查看文件列表
[[email protected] tmp]# unzip -l 123.zip     - l 选项 查看文件列表
Archive:  123.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  11-10-2017 21:55   123/
  3677600  11-10-2017 21:55   123/1.txt
---------                     -------
  3677600                     2 files

备注:

zip命令没有可以用 yum install -y zip 命令安装zip包;

unzip命令没有可以用 yum install -y unzip 命令安装unzip包。



6.6 tar打包

常用的参数:

  • -c 建立一个压缩文件的参数指令(create 的意思)
  • -v 压缩的过程中显示文件
  • -f 使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!
  • -t 查看 tarfile 里面的文件
  • -x 解开一个压缩文件的参数指令

示例:

  • tar -cvf 123.tar 123  仅打包,不压缩
[[email protected] tmp]# tree 123
123
├── 1.txt
├── 456
│   ├── 123
│   │   └── 1.txt
│   └── 456.zip
└── 789
    ├── 789.txt
    └── 789.txt.zip

3 directories, 5 files
[[email protected] tmp]# tar -cvf 123.tar 123
123/
123/1.txt
123/456/
123/456/123/
123/456/123/1.txt
123/456/456.zip
123/789/
123/789/789.txt.zip
123/789/789.txt
  • tar -cvf linux.tar 1.txt 123 打包1.txt文件和123目录,并重名为linux.tar
[[email protected] tmp]# tar -cvf linux.tar 1.txt 123
1.txt
123/
123/1.txt
123/456/
123/456/123/
123/456/123/1.txt
123/456/456.zip
123/789/
123/789/789.txt.zip
123/789/789.txt
[[email protected] tmp]# ls -lh linux.tar
-rw-r--r--. 1 root root 16M 11月 10 22:33 linux.tar       #容量比之前增加了
  • tar -xvf linux.tar 解开linux.tar包
[[email protected] tmp]# tar -xvf linux.tar
1.txt
123/
123/1.txt
123/456/
123/456/123/
123/456/123/1.txt
123/456/456.zip
123/789/
123/789/789.txt.zip
123/789/789.txt
  • tar -tf linux.tar  查看文件列表
[[email protected] tmp]# tar -tf linux.tar
1.txt
123/
123/1.txt
123/456/
123/456/123/
123/456/123/1.txt
123/456/456.zip
123/789/
123/789/789.txt.zip
123/789/789.txt
  • tar -cvf aming.tar --exclude 1.txt --exclude 2 123  过滤指定的文件
[[email protected] tmp]# tar -cvf linux.tar --exclude 1.txt --exclude 2 123
123/
123/456/
123/456/123/
123/456/456.zip
123/789/
123/789/789.txt.zip
123/789/789.txt


6.7 打包并压缩


时间: 2024-07-29 23:46:56

zip、tar工具的介绍及用法的相关文章

rpm、yum工具的介绍和用法

rpm介绍 RPM 是RPM Package Manager(RPM软件包管理器)的缩写,这一文件格式名称虽然打上了RedHat的标志,但是其原始设计理念是开放式的,现在包括OpenLinux.S.u.S.E.以及Turbo Linux等Linux的分发版本都有采用,可以算是公认的行业标准了. 用法: rpm -ivh rpm包文件 //安装 #搭建实验环境,找到安装光盘ISO文件 [[email protected] Packages]# mount /dev/cdrom /mnt/  挂载光

如何在Linux下创建与解压zip, tar, tar.gz和tar.bz2文件

这么多年来,数据压缩对我们来说是非常有用的.无论是在邮件中发送的图片用的zip文件还是在服务器压缩数据文件,我们都可以让下载更容易或者有效的节约磁盘空间.某些压缩格式有时允许我们以60%的比率(甚至更高)压缩文件.下面我将会给大家演示如何用这些命令在Linux下面去压缩文件或者目录.我们将学习zip, tar, tar.gz和tar.bz2等压缩格式的基本用法.这几个是在Linux里面常用的压缩格式. 在我们探究这些用法之前,我想先跟大家分享一下使用不同压缩格式的经验.当然,我这里讲到的只是其中

FileZip for mac(ZIP解压缩工具)

FileZip for mac是一款小巧实用的ZIP解压缩工具,它可以轻松解压压缩ZIP以及其他不同类型的压缩文件,您也可以使用密码保护它们.只需将要压缩的文件拖放到Dock或主窗口中的FileZip图标即可.macdown提供本软件下载. FileZip mac免费版软件介绍 FileZip Mac版是Mac平台上的一款解压缩工具.FileZip Mac版是一个小巧易用的程序,可以压缩或解压许多不同类型的压缩文件.使用FileZip Mac版,您可以根据需要压缩任意数量的文件.您也可以使用密码

Ubuntu解压缩zip,tar,tar.gz,tar.bz2

ZIP zip可能是目前使用得最多的文档压缩格式.它最大的优点就是在不同的操作系统平台,比如Linux, Windows以及Mac OS,上使用.缺点就是支持的压缩率不是很高,而tar.gz和tar.gz2在压缩率方面做得非常好.闲话少说,我们步入正题吧: 我们可以使用下列的命令压缩一个目录: # zip -r archive_name.zip directory_to_compress 下面是如果解压一个zip文档: # unzip archive_name.zip TAR Tar是在Linu

【硬件】DELL服务器硬件监控及DELL系统管理工具OMSA介绍

1.1.1. DELL服务器硬件监控及DELL系统管理工具OMSA介绍 本文介绍采用使用Nagios和OMSA监控DELL服务器的硬件健康状态,Nagios监控的方式是NRPE模式,需要配置check_openmanage脚本和安装DELL的OMSA工具. 使用OpenManage和Nagios监控DELL服务器硬件部署手册: http://folk.uio.no/trondham/software/check_openmanage.html 1)        OMSA是什么 OMSA是Del

网站压力测试工具Webbench介绍

Webbench是一个非常简单的压力测试工具,Webbench最多可以模拟3万个并发连接去测试网站的负载能力. (1)Webbench安装 wget http://www.phpddt.com/soft/linux/webbench-1.5.tar.gz tar zxvf webbench-1.5.tar.gz cd webbench-1.5 make make install (2)Webbench使用 webbench -c 1000 -t 60 http://www.phpddt.com/

如何在Linux下创建与解压,安装zip, tar, tar.gz和tar.bz2文件

zip可能是目前使用得最多的文档压缩格式.它最大的优点就是在不同的操作系统平台,比如Linux, Windows以及Mac OS,上使用.缺点就是支持的压缩率不是很高,而tar.gz和tar.gz2在压缩率方面做得非常好.闲话少说,我们步入正题吧: 我们可以使用下列的命令压缩一个目录: # zip -r archive_name.zip directory_to_compress 下面是如果解压一个zip文档: # unzip archive_name.zip TAR Tar是在Linux中使用

【转载】 AWK 工具简明介绍

有一些网友看了前两天的<Linux下应该知道的技巧>希望我能教教他们用awk和sed,所以,出现了这篇文章.我估计这些80后的年轻朋友可能对awk/sed这类上古神器有点陌生了,所以需要我这个老家伙来炒炒冷饭.况且,AWK是贝尔实验室1977年搞出来的文本出现神器,今年是蛇年,是AWK的本命年,而且年纪和我相仿,所以非常有必要为他写篇文章. 之所以叫AWK是因为其取了三位创始人 Alfred Aho,Peter Weinberger, 和 Brian Kernighan 的Family Nam

压缩解压归档gzip\bzip2\xz\zip\tar

常用工具 compress/uncompress .z gzip/gunzip .gz bzip2/bunzip2 .bz2 xz/unxz .xz zip/unzip .zip tar,cpio GZIP/GUNZIP/ZCAT,压缩文件 #gzip file 压缩后删除源文件 -d gunzip -c 输出到标准输出,加输出重定向>保存源文件 -0~9 压缩比例,默认6 #gunzip file 解压缩后删除源文件,相当于gzip -d file #zcat file 不展开的情况查看文本内