• Linux文件压缩、解压缩及归档工具一


    主题Linux文件压缩、解压缩及归档工具

    压缩工具很重要的,因为要经常到互联网下载包

     

    一compress/uncompress


    compress [-dfvcVr] [-b maxbits] [file ...]
    -d: 解压缩,相当于uncompress
    -c: 结果输出至标准输出,不删除原文件
    -v: 显示详情
    uncompress 解压缩
    zcat file.Z >file

    压缩涉及到压缩算法

    比如abcd出现了1000次,那么就可以使用a代替abcd

    不同的压缩方法压缩比不一样

    对文件进行压缩

    [root@centos72 ~]# ll  /var/log/messages
    -rw------- 1 root root 831851 May  2 17:01 /var/log/messages
    [root@centos72 ~]# ll  /var/log/messages  -h
    -rw------- 1 root root 813K May  2 17:01 /var/log/messages
    [root@centos72 ~]# cp  /var/log/messages    /app/m
    [root@centos72 ~]# ls  /app/m  -l
    -rw------- 1 root root 831851 May  2 17:31 /app/m
    [root@centos72 ~]# ls  /app/m  -lh
    -rw------- 1 root root 813K May  2 17:31 /app/m
    [root@centos72 ~]# ls  /app
    m
    [root@centos72 ~]# compress  /app/m
    -bash: compress: command not found
    
    [root@centos72 ~]# yum  whatprovides  compress 
    Loaded plugins: fastestmirror
    Repository base is listed more than once in the configuration
    Loading mirror speeds from cached hostfile
     * base: mirrors.zju.edu.cn
     * extras: ap.stykers.moe
     * updates: mirrors.tuna.tsinghua.edu.cn
    base/7/x86_64/filelists_db                                                       | 7.1 MB  00:00:01     
    extras/7/x86_64/filelists_db                                                     | 236 kB  00:00:00     
    updates/7/x86_64/filelists_db                                                    | 3.4 MB  00:00:00     
    ncompress-4.2.4.4-3.el7.x86_64 : Fast compression and decompression utilities
    Repo        : aliyun
    Matched from:
    Filename    : /usr/bin/compress
    
    
    
    ncompress-4.2.4.4-3.el7.x86_64 : Fast compression and decompression utilities
    Repo        : base
    Matched from:
    Filename    : /usr/bin/compress
    
    
    
    [root@centos72 ~]# yum  install   ncompress-4.2.4.4-3.el7.x86_64  -y
    Loaded plugins: fastestmirror
    Repository base is listed more than once in the configuration
    Loading mirror speeds from cached hostfile
     * base: mirrors.163.com
     * extras: mirrors.163.com
     * updates: mirrors.tuna.tsinghua.edu.cn
    Resolving Dependencies
    --> Running transaction check
    ---> Package ncompress.x86_64 0:4.2.4.4-3.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ========================================================================================================
     Package                 Arch                 Version                        Repository            Size
    ========================================================================================================
    Installing:
     ncompress               x86_64               4.2.4.4-3.el7                  aliyun                26 k
    
    Transaction Summary
    ========================================================================================================
    Install  1 Package
    
    Total download size: 26 k
    Installed size: 35 k
    Downloading packages:
    ncompress-4.2.4.4-3.el7.x86_64.rpm                                               |  26 kB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : ncompress-4.2.4.4-3.el7.x86_64                                                       1/1 
      Verifying  : ncompress-4.2.4.4-3.el7.x86_64                                                       1/1 
    
    Installed:
      ncompress.x86_64 0:4.2.4.4-3.el7                                                                      
    
    Complete!

    对文件进行压缩,并且重命名了

    [root@centos72 ~]# compress  /app/m
    [root@centos72 ~]# ls  /app
    m.Z
    [root@centos72 ~]# ls  /app  -l
    total 196
    -rw------- 1 root root 197701 May  2 17:31 m.Z
    [root@centos72 ~]# ls  /app  -lh
    total 196K
    -rw------- 1 root root 194K May  2 17:31 m.Z

    压缩比为1/4

    [root@centos72 ~]# diff   /var/log/messages  /app/m.Z 
    Binary files /var/log/messages and /app/m.Z differ
    [root@centos72 ~]# ll    /var/log/messages  /app/m.Z 
    -rw------- 1 root root 197701 May  2 17:31 /app/m.Z
    -rw------- 1 root root 831930 May  2 17:37 /var/log/messages
    [root@centos72 ~]# ll    /var/log/messages  /app/m.Z   -h
    -rw------- 1 root root 194K May  2 17:31 /app/m.Z
    -rw------- 1 root root 813K May  2 17:37 /var/log/messages
    [root@centos72 ~]# bc
    bc 1.06.95
    Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
    This is free software with ABSOLUTELY NO WARRANTY.
    For details type `warranty'. 
    813/194
    4

    -c: 结果输出至标准输出,也就是打印到屏幕上,不删除原文件

    我们可以把输出重定向到一个文件里面,这样还保留原文件

    [root@centos72 ~]# ls  /app
    m
    [root@centos72 ~]# ls  /app -l
    total 816
    -rw------- 1 root root 831851 May  2 17:31 m
    [root@centos72 ~]# compress    -c   /app/m  >   /app/m.z
    [root@centos72 ~]# ls  /app -l
    total 1012
    -rw------- 1 root root 831851 May  2 17:31 m
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# ls  /app 
    m  m.z

    解压缩compress -d或者uncompress或者zcat重定向到文件里面

    [root@centos72 ~]# uncompress    /app/m.Z 
    [root@centos72 ~]# ls  /app
    m
    [root@centos72 ~]# ls  /app  -l
    total 816
    -rw------- 1 root root 831851 May  2 17:31 m
    [root@centos72 ~]# ls  /app  -lh
    total 816K
    -rw------- 1 root root 813K May  2 17:31 m
    [root@centos72 ~]# ls  /app -l
    total 1012
    -rw------- 1 root root 831851 May  2 17:31 m
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# ls  /app 
    m  m.z
    [root@centos72 ~]# zcat   /app/m.z   >  /app/mm
    [root@centos72 ~]# ls /app
    m  mm  m.z
    [root@centos72 ~]# ls /app  -l
    total 1828
    -rw------- 1 root root 831851 May  2 17:31 m
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z

    二gzip/gunzip


    gzip [OPTION]... FILE ...
    -d: 解压缩,相当于gunzip
    -c: 将压缩或解压缩的结果输出至标准输出
    -#:1-9,指定压缩比,值越大压缩比越大
    zcat:不显式解压缩的前提下查看文本文件内容

    默认是使用压缩比6

     -# --fast --best
                  Regulate the speed of compression using the specified digit #, where -1 or --fast indi‐
                  cates the fastest compression method (less compression) and -9 or --best indicates  the
                  slowest  compression  method  (best  compression).  The default compression level is -6
                  (that is, biased towards high compression at expense of speed).
    [root@centos72 ~]# ls /app  -l
    total 1828
    -rw------- 1 root root 831851 May  2 17:31 m
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# ls /app  
    m  mm  m.z
    [root@centos72 ~]# gzip  m
    gzip: m: No such file or directory
    [root@centos72 ~]# gzip   /app/m
    [root@centos72 ~]# ls /app  -l
    total 1120
    -rw------- 1 root root 107731 May  2 17:31 m.gz
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# ls /app  -lh
    total 1.1M
    -rw------- 1 root root 106K May  2 17:31 m.gz
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z
    [root@centos72 ~]# bc
    bc 1.06.95
    Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
    This is free software with ABSOLUTELY NO WARRANTY.
    For details type `warranty'. 
    813/106
    7
    ^C
    (interrupt) Exiting bc.

    使用gzip进行解压、

    和compress类似,有多种方法

    [root@centos72 ~]# gzip   -d   /app/m.gz 
    [root@centos72 ~]# ls /app  -l
    total 1828
    -rw------- 1 root root 831851 May  2 17:31 m
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# ls /app  -lh
    total 1.8M
    -rw------- 1 root root 813K May  2 17:31 m
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z

    解压法2:

    [root@centos72 ~]# gzip  /app/m
    [root@centos72 ~]# ls /app  -l
    total 1120
    -rw------- 1 root root 107731 May  2 17:31 m.gz
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# gunzip   /app/m.gz 
    [root@centos72 ~]# ls /app  -l
    total 1828
    -rw------- 1 root root 831851 May  2 17:31 m
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z

    使用最高压缩比

    压缩比越高解压缩就会更慢

    压缩要靠CPU大量的做运算,会消耗CPU,不压缩就会占用磁盘空间,所以CPU性能和磁盘空间互换的

    raid是利用磁盘空间来换取高性能

    CPU很少出故障,但是内存和硬盘就经常出问题

    [root@centos72 ~]# gzip   -9   /app/m
    [root@centos72 ~]# ls /app  -l
    total 1116
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# ls /app  -lh
    total 1.1M
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z

    法3:

    [root@centos72 ~]# zcat   /app/m.gz   >  /app/mmm
    [root@centos72 ~]# ls /app  -l
    total 1932
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# ls /app  -lh
    total 1.9M
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z

    三bzip2/bunzip2/bzcat


    bzip2 [OPTION]... FILE ...
    -k: keep, 保留原文件
    -d:解压缩
    -#:1-9,压缩比,默认为9
    bzcat:不显式解压缩的前提下查看文本文件内容

    [root@centos72 ~]# bzip2
    -bash: bzip2: command not found
    [root@centos72 ~]# yum  whatprovides  bzip2
    Loaded plugins: fastestmirror
    Repository base is listed more than once in the configuration
    Loading mirror speeds from cached hostfile
     * base: mirrors.cn99.com
     * extras: mirrors.cn99.com
     * updates: mirrors.cn99.com
    bzip2-1.0.6-13.el7.x86_64 : A file compression utility
    Repo        : aliyun
    
    
    
    bzip2-1.0.6-13.el7.x86_64 : A file compression utility
    Repo        : base
    
    
    
    [root@centos72 ~]# yum  install   bzip2 -y
    Loaded plugins: fastestmirror
    Repository base is listed more than once in the configuration
    Loading mirror speeds from cached hostfile
     * base: mirrors.163.com
     * extras: mirrors.163.com
     * updates: mirrors.nwsuaf.edu.cn
    aliyun                                                                           | 3.6 kB  00:00:00     
    base                                                                             | 3.6 kB  00:00:00     
    extras                                                                           | 3.4 kB  00:00:00     
    updates                                                                          | 3.4 kB  00:00:00     
    Resolving Dependencies
    --> Running transaction check
    ---> Package bzip2.x86_64 0:1.0.6-13.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ========================================================================================================
     Package               Arch                   Version                      Repository              Size
    ========================================================================================================
    Installing:
     bzip2                 x86_64                 1.0.6-13.el7                 aliyun                  52 k
    
    Transaction Summary
    ========================================================================================================
    Install  1 Package
    
    Total download size: 52 k
    Installed size: 82 k
    Downloading packages:
    bzip2-1.0.6-13.el7.x86_64.rpm                                                    |  52 kB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : bzip2-1.0.6-13.el7.x86_64                                                            1/1 
      Verifying  : bzip2-1.0.6-13.el7.x86_64                                                            1/1 
    
    Installed:
      bzip2.x86_64 0:1.0.6-13.el7                                                                           
    
    Complete!
    [root@centos72 ~]# ls  /app
    m.gz  mm  mmm  m.z
    [root@centos72 ~]# ls  /app  -l
    total 1932
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# bzip2  /app/mm
    [root@centos72 ~]# ls  /app  -l
    total 1168
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z

    对文件解压缩

    [root@centos72 ~]# ls  /app  -l
    total 1168
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# bu
    build-locale-archive  builtin               bunzip2               busctl
    [root@centos72 ~]# bunzip2   /app/mm.bz2 
    [root@centos72 ~]# ls  /app  -l
    total 1932
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# ls  /app  -lh
    total 1.9M
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z

    直接保留原始文件

    -k: keep, 保留原文件

    [root@centos72 ~]# ls  /app  -lh
    total 1.9M
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z
    [root@centos72 ~]# bzip2  -k   /app/mm
    [root@centos72 ~]# ls  /app  -l
    total 1984
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    [root@centos72 ~]# ls  /app  -lh
    total 2.0M
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root  49K May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z

    注意zcat不关心后缀是什么,只要是压缩文件即可。

    压缩工具不仅关心是否为压缩文件,还关心文件的后缀

    [root@centos72 ~]# cp   /app/m.gz   /app/m.gz.txt
    [root@centos72 ~]# ls  /app  -lh
    total 2.1M
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw------- 1 root root 104K May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root  49K May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z
    [root@centos72 ~]# zcat   /app/m.gz.txt  >  /app/m1
    [root@centos72 ~]# ls  /app  -lh
    total 2.9M
    -rw-r--r-- 1 root root 813K May  2 23:00 m1
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw------- 1 root root 104K May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root  49K May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z

    报错,因为后缀不对

    [root@centos72 ~]# gunzip   /app/m.gz.txt
    gzip: /app/m.gz.txt: unknown suffix -- ignored

    显示的是压缩文件

    [root@centos72 ~]# file  /app/m.gz.txt 
    /app/m.gz.txt: gzip compressed data, was "m", from Unix, last modified: Thu May  2 17:31:31 2019, max compression

    四xz/unxz/xzcat


    xz [OPTION]... FILE ...
    -k: keep, 保留原文件
    -d:解压缩
    -#:1-9,压缩比,默认为6
    xzcat: 不显式解压缩的前提下查看文本文件内容

    文件大小排序

    [root@centos72 ~]# ls  /app  -l
    total 2904
    -rw-r--r-- 1 root root 831851 May  2 23:00 m1
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw------- 1 root root 106019 May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    
    [root@centos72 ~]# ll  /app  -S
    total 2904
    -rw-r--r-- 1 root root 831851 May  2 23:00 m1
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw------- 1 root root 106019 May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2

    xz的压缩比更高,但是因为出现的比较晚,有些压缩包不支持

    [root@centos72 ~]# xz  /app/mm
    [root@centos72 ~]# ll  /app  -S
    total 2128
    -rw-r--r-- 1 root root 831851 May  2 23:00 m1
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw------- 1 root root 106019 May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root  40768 May  2 17:58 mm.xz
    [root@centos72 ~]# ll  /app  -Sh
    total 2.1M
    -rw-r--r-- 1 root root 813K May  2 23:00 m1
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw------- 1 root root 104K May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root  49K May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root  40K May  2 17:58 mm.xz

    对文件解压缩

    [root@centos72 ~]# ll  /app  -Sh
    total 2.1M
    -rw-r--r-- 1 root root 813K May  2 23:00 m1
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw------- 1 root root 104K May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root  49K May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root  40K May  2 17:58 mm.xz
    [root@centos72 ~]# xz  -d  /app/mm.xz 
    [root@centos72 ~]# ll  /app  -Sh
    total 2.9M
    -rw-r--r-- 1 root root 813K May  2 23:00 m1
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw------- 1 root root 104K May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root  49K May  2 17:58 mm.bz2
    [root@centos72 ~]# 

    注意gz和bzp2的压缩包是最多的

    五zip/unzip


    zip    –r   /etc/sysconfig/ 表示压缩目录

    zip    /etc/sysconfig表示压缩文件


    解包解压缩
    unzip sysconfig.zip
    cat /var/log/messages | zip messages -
    unzip -p message > message

    [root@centos72 ~]# zip 
    -bash: zip: command not found
    [root@centos72 ~]# yum  whatprovides  zip
    Loaded plugins: fastestmirror
    Repository base is listed more than once in the configuration
    Loading mirror speeds from cached hostfile
     * base: mirrors.cn99.com
     * extras: mirrors.cn99.com
     * updates: mirrors.cn99.com
    zip-3.0-11.el7.x86_64 : A file compression and packaging utility compatible with PKZIP
    Repo        : aliyun
    
    
    
    zip-3.0-11.el7.x86_64 : A file compression and packaging utility compatible with PKZIP
    Repo        : base
    
    
    
    [root@centos72 ~]# yum  install   zip  -y
    Loaded plugins: fastestmirror
    Repository base is listed more than once in the configuration
    Loading mirror speeds from cached hostfile
     * base: mirrors.zju.edu.cn
     * extras: mirrors.zju.edu.cn
     * updates: mirrors.tuna.tsinghua.edu.cn
    Resolving Dependencies
    --> Running transaction check
    ---> Package zip.x86_64 0:3.0-11.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ========================================================================================================
     Package              Arch                    Version                     Repository               Size
    ========================================================================================================
    Installing:
     zip                  x86_64                  3.0-11.el7                  aliyun                  260 k
    
    Transaction Summary
    ========================================================================================================
    Install  1 Package
    
    Total download size: 260 k
    Installed size: 796 k
    Downloading packages:
    zip-3.0-11.el7.x86_64.rpm                                                        | 260 kB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : zip-3.0-11.el7.x86_64                                                                1/1 
      Verifying  : zip-3.0-11.el7.x86_64                                                                1/1 
    
    Installed:
      zip.x86_64 0:3.0-11.el7                                                                               
    
    Complete!
    [root@centos72 ~]# zip  -r   /app/sysconfig  /etc/sysconfig/
      adding: etc/sysconfig/ (stored 0%)
      adding: etc/sysconfig/ip6tables-config (deflated 61%)
      adding: etc/sysconfig/iptables-config (deflated 60%)
      adding: etc/sysconfig/cbq/ (stored 0%)
      adding: etc/sysconfig/cbq/avpkt (stored 0%)
      adding: etc/sysconfig/cbq/cbq-0000.example (deflated 9%)
      adding: etc/sysconfig/rdisc (stored 0%)
      adding: etc/sysconfig/console/ (stored 0%)
      adding: etc/sysconfig/init (deflated 52%)
      adding: etc/sysconfig/modules/ (stored 0%)
      adding: etc/sysconfig/netconsole (deflated 50%)
      adding: etc/sysconfig/network-scripts/ (stored 0%)
      adding: etc/sysconfig/network-scripts/ifcfg-lo (deflated 25%)
      adding: etc/sysconfig/network-scripts/ifdown (deflated 59%)
      adding: etc/sysconfig/network-scripts/ifdown-bnep (deflated 43%)
      adding: etc/sysconfig/network-scripts/ifdown-eth (deflated 64%)
      adding: etc/sysconfig/network-scripts/ifdown-ippp (deflated 54%)
      adding: etc/sysconfig/network-scripts/ifdown-ipv6 (deflated 62%)
      adding: etc/sysconfig/network-scripts/ifdown-isdn (deflated 54%)
      adding: etc/sysconfig/network-scripts/ifdown-post (deflated 57%)
      adding: etc/sysconfig/network-scripts/ifdown-ppp (deflated 58%)
      adding: etc/sysconfig/network-scripts/ifdown-routes (deflated 50%)
      adding: etc/sysconfig/network-scripts/ifdown-sit (deflated 50%)
      adding: etc/sysconfig/network-scripts/ifdown-tunnel (deflated 44%)
      adding: etc/sysconfig/network-scripts/ifup (deflated 63%)
      adding: etc/sysconfig/network-scripts/ifup-aliases (deflated 66%)
      adding: etc/sysconfig/network-scripts/ifup-bnep (deflated 47%)
      adding: etc/sysconfig/network-scripts/ifup-eth (deflated 68%)
      adding: etc/sysconfig/network-scripts/ifup-ippp (deflated 72%)
      adding: etc/sysconfig/network-scripts/ifup-ipv6 (deflated 70%)
      adding: etc/sysconfig/network-scripts/ifup-isdn (deflated 72%)
      adding: etc/sysconfig/network-scripts/ifup-plip (deflated 45%)
      adding: etc/sysconfig/network-scripts/ifup-plusb (deflated 48%)
      adding: etc/sysconfig/network-scripts/ifup-post (deflated 65%)
      adding: etc/sysconfig/network-scripts/ifup-ppp (deflated 63%)
      adding: etc/sysconfig/network-scripts/ifup-routes (deflated 63%)
      adding: etc/sysconfig/network-scripts/ifup-sit (deflated 62%)
      adding: etc/sysconfig/network-scripts/ifup-tunnel (deflated 51%)
      adding: etc/sysconfig/network-scripts/ifup-wireless (deflated 49%)
      adding: etc/sysconfig/network-scripts/init.ipv6-global (deflated 70%)
      adding: etc/sysconfig/network-scripts/network-functions (deflated 71%)
      adding: etc/sysconfig/network-scripts/network-functions-ipv6 (deflated 79%)
      adding: etc/sysconfig/network-scripts/ifdown-Team (deflated 44%)
      adding: etc/sysconfig/network-scripts/ifdown-TeamPort (deflated 45%)
      adding: etc/sysconfig/network-scripts/ifup-Team (deflated 45%)
      adding: etc/sysconfig/network-scripts/ifup-TeamPort (deflated 50%)
      adding: etc/sysconfig/network-scripts/ifcfg-ens33 (deflated 25%)
      adding: etc/sysconfig/network-scripts/ifcfg-ens37 (deflated 24%)
      adding: etc/sysconfig/readonly-root (deflated 50%)
      adding: etc/sysconfig/crond (deflated 15%)
      adding: etc/sysconfig/run-parts (stored 0%)
      adding: etc/sysconfig/selinux (deflated 49%)
      adding: etc/sysconfig/wpa_supplicant (deflated 44%)
      adding: etc/sysconfig/ebtables-config (deflated 61%)
      adding: etc/sysconfig/grub (deflated 23%)
      adding: etc/sysconfig/irqbalance (deflated 45%)
      adding: etc/sysconfig/man-db (deflated 30%)
      adding: etc/sysconfig/rsyslog (deflated 23%)
      adding: etc/sysconfig/firewalld (stored 0%)
      adding: etc/sysconfig/kdump (deflated 50%)
      adding: etc/sysconfig/sshd (deflated 41%)
      adding: etc/sysconfig/authconfig (deflated 47%)
      adding: etc/sysconfig/cpupower (deflated 25%)
      adding: etc/sysconfig/kernel (deflated 34%)
      adding: etc/sysconfig/network (stored 0%)
      adding: etc/sysconfig/anaconda (deflated 54%)
      adding: etc/sysconfig/chronyd (stored 0%)
      adding: etc/sysconfig/ntpdate (deflated 6%)
      adding: etc/sysconfig/ntpd (stored 0%)
      adding: etc/sysconfig/keepalived (deflated 46%)
      adding: etc/sysconfig/ipvsadm-config (deflated 53%)
      adding: etc/sysconfig/nginx (deflated 11%)
      adding: etc/sysconfig/nginx-debug (deflated 22%)
      adding: etc/sysconfig/htcacheclean (deflated 30%)
      adding: etc/sysconfig/httpd (deflated 44%)
    [root@centos72 ~]# ll  /app  
    total 2984
    -rw-r--r-- 1 root root 831851 May  2 23:00 m1
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw------- 1 root root 106019 May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    -rw-r--r-- 1 root root  80145 May  2 23:24 sysconfig.zip

    解压缩

    法2:

    [root@centos72 ~]# ls  /app
    m1  m.gz  m.gz.txt  mm  mm.bz2  mmm  m.z  sysconfig.zip
    [root@centos72 ~]# ls  /app  -lh
    total 3.0M
    -rw-r--r-- 1 root root 813K May  2 23:00 m1
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw------- 1 root root 104K May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root  49K May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z
    -rw-r--r-- 1 root root  79K May  2 23:24 sysconfig.zip
    [root@centos72 ~]# cat /var/log/messages | zip  /app/messages -
      adding: - (deflated 87%)
    [root@centos72 ~]# ls  /app  -lh
    total 3.1M
    -rw-r--r-- 1 root root 813K May  2 23:00 m1
    -rw-r--r-- 1 root root 106K May  2 23:28 messages.zip
    -rw------- 1 root root 104K May  2 17:31 m.gz
    -rw------- 1 root root 104K May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root  49K May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z
    -rw-r--r-- 1 root root  79K May  2 23:24 sysconfig.zip
    [root@centos72 ~]# ll /var/log/messages
    -rw------- 1 root root 832545 May  2 23:23 /var/log/messages
    [root@centos72 ~]# ll /var/log/messages  -h
    -rw------- 1 root root 814K May  2 23:23 /var/log/messages
    [root@centos72 ~]# 
    [root@centos72 ~]# unzip   -p    /app/messages.zip  
    -bash: unzip: command not found
    [root@centos72 ~]# yum  whatprovides  unzip  
    Loaded plugins: fastestmirror
    Repository base is listed more than once in the configuration
    Loading mirror speeds from cached hostfile
     * base: mirrors.163.com
     * extras: mirrors.163.com
     * updates: mirrors.cn99.com
    unzip-6.0-19.el7.x86_64 : A utility for unpacking zip files
    Repo        : aliyun
    
    
    
    unzip-6.0-19.el7.x86_64 : A utility for unpacking zip files
    Repo        : base
    
    
    
    [root@centos72 ~]# yum  install  unzip  
    Loaded plugins: fastestmirror
    Repository base is listed more than once in the configuration
    Loading mirror speeds from cached hostfile
     * base: mirrors.cn99.com
     * extras: mirrors.cn99.com
     * updates: mirrors.cn99.com
    Resolving Dependencies
    --> Running transaction check
    ---> Package unzip.x86_64 0:6.0-19.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ========================================================================================================
     Package               Arch                   Version                      Repository              Size
    ========================================================================================================
    Installing:
     unzip                 x86_64                 6.0-19.el7                   aliyun                 170 k
    
    Transaction Summary
    ========================================================================================================
    Install  1 Package
    
    Total download size: 170 k
    Installed size: 365 k
    Is this ok [y/d/N]: y
    Downloading packages:
    unzip-6.0-19.el7.x86_64.rpm                                                      | 170 kB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : unzip-6.0-19.el7.x86_64                                                              1/1 
      Verifying  : unzip-6.0-19.el7.x86_64                                                              1/1 
    
    Installed:
      unzip.x86_64 0:6.0-19.el7                                                                             
    
    Complete!

    unzip -p进行解压缩

    [root@centos72 ~]# unzip  -p   /app/messages.zip    >  /app/messages
    [root@centos72 ~]# ll /app
    total 3908
    -rw-r--r-- 1 root root 831851 May  2 23:00 m1
    -rw-r--r-- 1 root root 832545 May  2 23:37 messages
    -rw-r--r-- 1 root root 108052 May  2 23:28 messages.zip
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    -rw------- 1 root root 106019 May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    -rw-r--r-- 1 root root  80145 May  2 23:24 sysconfig.zip
    [root@centos72 ~]# ll /app  -ht
    total 3.9M
    -rw-r--r-- 1 root root 814K May  2 23:37 messages
    -rw-r--r-- 1 root root 106K May  2 23:28 messages.zip
    -rw-r--r-- 1 root root  79K May  2 23:24 sysconfig.zip
    -rw-r--r-- 1 root root 813K May  2 23:00 m1
    -rw------- 1 root root 104K May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 813K May  2 22:46 mmm
    -rw-r--r-- 1 root root 813K May  2 17:58 mm
    -rw-r--r-- 1 root root  49K May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 194K May  2 17:55 m.z
    -rw------- 1 root root 104K May  2 17:31 m.gz

    创建文件并且设置无权限

    [root@centos72 ~]# touch   /app/aa.txt
    [root@centos72 ~]# ll  /app/aa.txt 
    -rw-r--r-- 1 root root 0 May  2 23:42 /app/aa.txt
    [root@centos72 ~]# echo   abcdefghijklmn  >  /app/aa.txt 
    [root@centos72 ~]# ll  /app/aa.txt 
    -rw-r--r-- 1 root root 15 May  2 23:42 /app/aa.txt
    [root@centos72 ~]# chmod   0   /app/aa.txt 
    [root@centos72 ~]# ll  /app/aa.txt 
    ---------- 1 root root 15 May  2 23:42 /app/aa.txt

    对文件进行压缩

    [root@centos72 ~]# xz  /app/aa.txt   
    [root@centos72 ~]# ll  /app/  -t
    total 3912
    ---------- 1 root root     72 May  2 23:42 aa.txt.xz
    -rw-r--r-- 1 root root 832545 May  2 23:37 messages
    -rw-r--r-- 1 root root 108052 May  2 23:28 messages.zip
    -rw-r--r-- 1 root root  80145 May  2 23:24 sysconfig.zip
    -rw-r--r-- 1 root root 831851 May  2 23:00 m1
    -rw------- 1 root root 106019 May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    -rw------- 1 root root 106019 May  2 17:31 m.gz

    对文件进行解压缩,文件的属性保留下来了

    [root@centos72 ~]# xz  -d  /app/aa.txt.xz 
    [root@centos72 ~]# ll  /app/  -t
    total 3912
    ---------- 1 root root     15 May  2 23:42 aa.txt
    -rw-r--r-- 1 root root 832545 May  2 23:37 messages
    -rw-r--r-- 1 root root 108052 May  2 23:28 messages.zip
    -rw-r--r-- 1 root root  80145 May  2 23:24 sysconfig.zip
    -rw-r--r-- 1 root root 831851 May  2 23:00 m1
    -rw------- 1 root root 106019 May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    -rw------- 1 root root 106019 May  2 17:31 m.gz

    设置acl权限

    压缩和解压都少了acl权限

    所以对于acl要单独做备份

    [root@centos72 ~]# setfacl   -m   u:wang:rwx   /app/aa.txt 
    [root@centos72 ~]# ll  /app/aa.txt 
    ----rwx---+ 1 root root 15 May  2 23:42 /app/aa.txt
    [root@centos72 ~]# xz  /app/aa.txt 
    [root@centos72 ~]# ll  /app/  -t
    total 3912
    ----rwx--- 1 root root     72 May  2 23:42 aa.txt.xz
    -rw-r--r-- 1 root root 832545 May  2 23:37 messages
    -rw-r--r-- 1 root root 108052 May  2 23:28 messages.zip
    -rw-r--r-- 1 root root  80145 May  2 23:24 sysconfig.zip
    -rw-r--r-- 1 root root 831851 May  2 23:00 m1
    -rw------- 1 root root 106019 May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    -rw------- 1 root root 106019 May  2 17:31 m.gz
    [root@centos72 ~]# xz -d   /app/aa.txt.xz 
    [root@centos72 ~]# ll  /app/  -t
    total 3912
    ----rwx--- 1 root root     15 May  2 23:42 aa.txt
    -rw-r--r-- 1 root root 832545 May  2 23:37 messages
    -rw-r--r-- 1 root root 108052 May  2 23:28 messages.zip
    -rw-r--r-- 1 root root  80145 May  2 23:24 sysconfig.zip
    -rw-r--r-- 1 root root 831851 May  2 23:00 m1
    -rw------- 1 root root 106019 May  2 22:59 m.gz.txt
    -rw-r--r-- 1 root root 831851 May  2 22:46 mmm
    -rw-r--r-- 1 root root 831851 May  2 17:58 mm
    -rw-r--r-- 1 root root  49513 May  2 17:58 mm.bz2
    -rw-r--r-- 1 root root 197701 May  2 17:55 m.z
    -rw------- 1 root root 106019 May  2 17:31 m.gz


    作者:wang618
    出处:https://www.cnblogs.com/wang618/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。

  • 相关阅读:
    windows上设置代理
    docker 代理
    windbg随笔
    win10自带ssh server使用
    centos7 最小安装后,编译配置redsocks
    cef chromium 编译
    C++中的单例模式
    delete NULL
    音视频通讯能力提供商
    云视频会议解决方案
  • 原文地址:https://www.cnblogs.com/wang618/p/11176747.html
Copyright © 2020-2023  润新知