zip压缩工具,tar打包,打包并压缩

zip 压缩工具

  • 支持压缩目录

  • 安装:yum install -y zip

[[email protected] ddd]# tree
.
├── 111
│?? ├── 1.txt
│?? └── 222
│??     └── 333
│??         └── 444
├── 1.txt
└── 2.txt.bz2.xz

4 directories, 3 files
[[email protected] ddd]# du -sh 111/
2.0M    111/
[[email protected] ddd]# yum install -y zip
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.hosteurope.de
 * extras: ftp.hosteurope.de
 * updates: ftp.hosteurope.de
正在解决依赖关系
--> 正在检查事务
---> 软件包 zip.x86_64.0.3.0-11.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

====================================================================================================================================================
 Package                         架构                               版本                                     源                                大小
====================================================================================================================================================
正在安装:
 zip                             x86_64                             3.0-11.el7                               base                             260 k

事务概要
====================================================================================================================================================
安装  1 软件包

总下载量:260 k
安装大小:796 k
Downloading packages:
zip-3.0-11.el7.x86_64.rpm                                                                                                    | 260 kB  00:00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : zip-3.0-11.el7.x86_64                                                                                                           1/1
  验证中      : zip-3.0-11.el7.x86_64                                                                                                           1/1 

已安装:
  zip.x86_64 0:3.0-11.el7                                                                                                                           

完毕!
  • 用法:zip 1.txt.zip 1.txt

[[email protected] ddd]# zip 1.txt.zip 1.txt
  adding: 1.txt (deflated 74%)
[[email protected] ddd]# ls
111  1.txt  1.txt.zip  2.txt.bz2.xz
[[email protected] ddd]# du -sh 1.txt.zip
524K    1.txt.zip
[[email protected] ddd]#
    • 压缩目录:zip -r

[[email protected] ddd]# zip -r 111.zip 111/
  adding: 111/ (stored 0%)
  adding: 111/222/ (stored 0%)
  adding: 111/222/333/ (stored 0%)
  adding: 111/222/333/444/ (stored 0%)
  adding: 111/1.txt (deflated 74%)
[[email protected] ddd]# ls
111  111.zip  1.txt  1.txt.zip  2.txt.bz2.xz
[[email protected] ddd]#

压缩完之后源文件不消失

  • 解压缩:unzip

没有先安装一下:yum install -y unzip

  • 解压到指定目录:unzip 1.txt.zip -d 目录/

[[email protected] ddd]# unzip 1.txt.zip -d /tmp/567/
Archive:  1.txt.zip
  inflating: /tmp/567/1.txt
[[email protected] ddd]# ls -sh /tmp/567/
总用量 2.0M
2.0M 1.txt
[[email protected] ddd]# 
  • zip是不能直接查看内容

  • 只能查看文件列表:unzip -l 111.zip

[[email protected] ddd]# unzip -l 111.zip
Archive:  111.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  08-25-2017 21:45   111/
        0  08-25-2017 21:43   111/222/
        0  08-25-2017 21:43   111/222/333/
        0  08-25-2017 21:43   111/222/333/444/
  2043960  08-25-2017 21:45   111/1.txt
---------                     -------
  2043960                     5 files
[[email protected] ddd]#

tar打包工具

  • 用法:

    • -x : 表示解压缩
    • -t : 查看tar包里的文件
    • -v : 表示可视化
    • -c : 建立一个tar包或者压缩文件
    • -f : 后面跟文件名(表示压缩或解压后的文件名是什么),要注意如果是多个参数组合的情况下,-f 参数写到最后面。
    • -z : 同时用gzip压缩
    • -j : 同时用bzip2压缩
    • -J: 同时用xz压缩
    • --exclude :打包时过滤文件

打包命令:tar -cvf aminglinux.tar 111/

[[email protected] ddd]# tar -cvf aminglinux.tar 111/
111/
111/222/
111/222/333/
111/222/333/444/
111/1.txt
[[email protected] ddd]# ls
111  111.zip  1.txt  1.txt.zip  2.txt.bz2.xz  aminglinux.tar

解包命令:tar -xvf aminglinux.tar 111/

[[email protected] ddd]# tar -xvf aminglinux.tar 111/
111/
111/222/
111/222/333/
111/222/333/444/
111/1.txt

解包直接覆盖原目录

  • 打包也可以打包目录,文件,目录和文件

  • 查看tar包:tar -tf aminglinux.tar

[[email protected] ddd]# tar -tf aminglinux.tar
111/
111/222/
111/222/333/
111/222/333/444/
111/1.txt
[[email protected] ddd]#
  • 打包时过滤文件:--exclude

用法:tar -cvf tar包 --exclude 需要过滤的文件名 打包的文件

[[email protected] ddd]# tar -cvf  aminglinux.tar --exclude 1.txt  111/
111/
111/222/
111/222/333/
111/222/333/444/
[[email protected] ddd]#

还可以这样用

[[email protected] ddd]# tar -cvf  aminglinux.tar --exclude "*.txt"  111/
111/
111/222/
111/222/333/
111/222/333/444/
  • -z : 打包同时用gzip压缩

[[email protected] ddd]# tar -czvf aminglinux.tar.gz 1.txt 111
1.txt
111/
111/222/
111/222/333/
111/222/333/444/
111/1.txt
[[email protected] ddd]# ls
111  111.zip  1.txt  1.txt.zip  2.txt.bz2.xz  aminglinux.tar  aminglinux.tar.gz  --exclude
[[email protected] ddd]# du -sh aminglinux.tar.gz
1.1M    aminglinux.tar.gz
[[email protected] ddd]# du -sh 111/ 1.txt
2.0M    111/
2.0M    1.txt
[[email protected] ddd]# 
  • -j : 打包同时用bzip2压缩

[[email protected] ddd]# tar -cjvf aminglinux.tar.bz2 1.txt 111
1.txt
111/
111/222/
111/222/333/
111/222/333/444/
111/1.txt
[[email protected] ddd]# du -sh aminglinux.tar.bz2
424K    aminglinux.tar.bz2
[[email protected] ddd]#
  • -J: 同时用xz压缩

[[email protected] ddd]# tar -cJvf aminglinux.tar.xz 1.txt 111
1.txt
111/
111/222/
111/222/333/
111/222/333/444/
111/1.txt
[[email protected] ddd]# du -sh aminglinux.tar.xz
60K aminglinux.tar.xz
[[email protected] ddd]#

原文地址:http://blog.51cto.com/11751505/2104164

时间: 2024-08-30 09:10:47

zip压缩工具,tar打包,打包并压缩的相关文章

zip压缩工具 tar打包 打包并压缩

6.5 zip压缩工具 6.6 tar打包 6.7 打包并压缩 zip压缩工具 xz,bzip2,gzip都不支持压缩目录 zip可以压缩目录 压缩文件 zip  2.txt.zip  2.txt [[email protected] ~]# zip 2.txt.zip 2.txt adding: 2.txt (deflated 99%) [[email protected] ~]# du -sh * 108K 2.txt 4.0K 2.txt.zip 压缩目录+文件 zip  -r  test

zip压缩工具 tar打包打包并压缩

zip压缩工具 zip支持压缩目录.并且源文件不删除.先yum安装zip ·zip压缩文件:zip+压缩后的文件名+源文件名如压缩1.txtzip 1.txt.zip 1.txt·-r:压缩目录,如下图将1.txt和yang压缩并取名为y.zip·zip有一个特点,压缩后不会删除原文件,我们还是可以看到原文件的·unzip:解压(如果提示未找到命令就安装unzip包)·因为zip 的特点是不会删除原文件,所以我们解压的时候会提示是否覆盖,A是全部覆盖·-d:指定解压到哪里,如下图(unzip后面

zip压缩工具 tar打包并压缩

一.zip压缩工具zip支持压缩目录#zip filename.zip filename //使用zip命令压缩filename文件#zip -r aaa.zip aaa //压缩目录需要加-r ,使用zip命令压缩aaa目录#unzip //解压缩命令#unzip aaa.zip -d bbb/ //-d 指定aaa.zip文件解压到bbb目录下#unzip -l aaa.zip //查看aaa.zip的文件列表,不能查看内容 二.tar打包工具#tar -cvf aaa.tar aaa/ /

6.5 zip压缩工具 6.6 tar打包 6.7 打包并压缩

- 6.5 zip压缩工具 - 6.6 tar打包 - 6.7 打包并压缩 #  6.5 zip压缩工具 - zip压缩工具可以压缩目录 - 压缩目录需要用zip -r ``` [[email protected] d6z]# ls 1.txt.bz2  2.txt  2.txt.zip  3.txt  4.txt  aminglinux [[email protected] d6z]# zip -r aming.zip 3.txt aminglinux adding: 3.txt (defla

zip压缩工具、tar打包、打包并压缩

一.zip压缩工具 zip支持压缩目录和文件.zip压缩的文件后缀名为.zip.yum install -y zip  #安装zip压缩工具 zip命令压缩文件:zip 压缩包名 被压缩的文件名.后缀名以.zip结尾. zip命令压缩目录:zip -r 压缩包名 被压缩的目录(文件).后缀名以.zip结尾. zip压缩与bzip2.xz.gzip压缩的不同之处在于,zip压缩后原文件还在,其它三种压缩后原文件就不在了. unzip解压缩:unzip 压缩包. 当解压的目录下存在相同名字的文件,系

6.5 zip压缩工具;6.6 tar打包;6.7 打包并压缩

6.5 zip压缩工具 yum安装zip压缩工具: [[email protected] ~]# yum install -y zip 1. zip压缩文件:zip 压缩文件名 原文件 [[email protected] ~]# zip hao.txt.zip hao.txt 2. zip压缩目录:zip -r   压缩目录名 原目录 [[email protected] ~]# zip -r mulu1.zip mulu yum安装zip解压工具: [[email protected] ~]

二十、zip压缩工具、tar打包、打包并压缩

一.zip压缩工具 在Windows和Linux中都常用.可以压缩目录和文件,压缩目录时,需要指定目录下的文件.压缩后源文件不删除.示例: # zip 1.txt.zip 1.txt (压缩文件,先目标文件名,再源文件名) adding: 1.txt (deflated 64%) 压缩目录时需要加上-r选项,如下: # zip -r 1.txt.zip 1/ adding: 1/ (stored 0%) adding: 1/11/ (stored 0%) adding: 1/11/111/ (s

Linux CentOS 7 中打包压缩工具gzip、bzip2、xz、zip、tar

一. 压缩打包介绍 常见压缩文件 windows .rar  .zip  .7z linux: .rar .zip .gz .bz2 .xz .tar.gz .tar.bz2  .tar.xz 二. gzip压缩工具 gzip压缩文件: gzip 只能压缩文件不能压缩目录.**gzip 1.txt 压缩完成原文件删除**生成1.txt文件: find /etc/ -type f -name  "*.conf" -exec cat {} >> /tmp/fxq/1.txt \

linux的zip、tar压缩打包工具介绍

zip压缩工具: 1.安装zip命令工具 yum install -y zip 2.zip压缩工具既可以压缩文件也可以压缩目录,而且压缩的时候不会源文件删除,示例如下: [[email protected] d6z]# ls                 //查看目录下的文件 1.txt.bz2  2.txt  3.txt  4.txt  aminglinux [[email protected] d6z]# zip 2.txt.zip 2.txt         //使用zip压缩2.txt