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

 

转载于:https://www.cnblogs.com/wang618/p/11176747.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux下的rar解压缩工具: RAR 5.60 beta 1 Copyright (c) 1993-2018 Alexander Roshal 21 Mar 2018 Trial version Type 'rar -?' for help Usage: rar <command> -<switch 1> -<switch N> <archive> <files...> <@listfiles...> <path_to_extract\> <Commands> a Add files to archive c Add archive comment ch Change archive parameters cw Write archive comment to file d Delete files from archive e Extract files without archived paths f Freshen files in archive i[par]=<str> Find string in archives k Lock archive l[t[a],b] List archive contents [technical[all], bare] m[f] Move to archive [files only] p Print file to stdout r Repair archive rc Reconstruct missing volumes rn Rename archived files rr[N] Add data recovery record rv[N] Create recovery volumes s[name|-] Convert archive to or from SFX t Test archive files u Update files in archive v[t[a],b] Verbosely list archive contents [technical[all],bare] x Extract files with full path <Switches> - Stop switches scanning @[+] Disable [enable] file lists ad Append archive name to destination path ag[format] Generate archive name using the current date ai Ignore file attributes ap<path> Set path inside archive as Synchronize archive contents c- Disable comments show cfg- Disable read configuration cl Convert names to lower case cu Convert names to upper case df Delete files after archiving dh Open shared files ds Disable name sort for solid archive dw Wipe files after archiving e[+]<attr> Set file exclude and include attributes ed Do not add empty directories en Do not put 'end of archive' block ep Exclude paths from names ep1 Exclude base directory from names ep3 Expand paths to full including the drive letter f Freshen files hp[password] Encrypt both file data and headers ht[b|c] Select hash type [BLAKE2,CRC32] for file checksum id[c,d,p,q] Disable messages ierr Send all messages to stderr ilog[name] Log errors to file inul Disable all messages isnd Enable sound iver Display the version number k Lock archive kb Keep broken extracted files log[f][=name] Write names to log file m<0..5> Set compression level (0-store...3-default...5-maximal) ma[4|5] Specify a version of archiving format mc<par> Set advanced compression parameters md<n>[k,m,g] Dictionary size in KB, MB or GB ms[ext;ext] Specify file types to store mt<threads> Set the number of threads n<file> Additionally filter included files n@ Read additional filter masks from stdin n@<list> Read additional filter masks from list file o[+|-] Set the overwrite mode oh Save hard links as the link instead of the file oi[0-4][:min] Save identical files as references ol[a] Process symbolic links as the link [absolute paths] or Rename files automatically ow Save or restore file owner and group p[password] Set password p- Do not query password qo[-|+] Add quick open information [none|force] r Recurse subdirectories r- Disable recursion r0 Recurse subdirectories for wildcard names only rr[N] Add data recovery record rv[N] Create recovery volumes s[<N>,v[-],e] Create solid archive s- Disable solid archiving sc<chr>[obj] Specify the character set sfx[name] Create SFX archive si[name] Read data from standard input (stdin) sl<size> Process files with size less than specified sm<size> Process files with size more than specified t Test files after archiving ta<date> Process files modified after <date> in YYYYMMDDHHMMSS format tb<date> Process files modified before <date> in YYYYMMDDHHMMSS format tk Keep original archive time tl Set archive time to latest file tn<time> Process files newer than <time> to<time> Process files older than <time> ts[m|c|a] Save or restore file time (modification, creation, access) u Update files v<size>[k,b] Create volumes with size=<size>*1000 [*1024, *1] ver[n] File version control vn Use the old style volume naming scheme vp Pause before each volume w<path> Assign work directory x<file> Exclude specified file x@ Read file names to exclude from stdin x@<list> Exclude files listed in specified list file y Assume Yes on all queries z[file] Read archive comment from file

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值