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
-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
Linux文件压缩、解压缩及归档工具一的更多相关文章
- linux压缩、解压缩和归档工具
linux基础之压缩.解压缩和归档工具 1.压缩工具 基本介绍 为了减少文件的原来的文件大小而过多的浪费磁盘的存储空间,我们使用压缩后多文件进行存储 压缩工具的介绍 compress:把文件压缩成以. ...
- Linux的压缩/解压缩文件处理 zip & unzip
Linux的压缩/解压缩命令详解及实例 压缩服务器上当前目录的内容为xxx.zip文件 zip -r xxx.zip ./* 解压zip文件到当前目录 unzip filename.zip 另:有些服 ...
- Linux 文件压缩与归档
.note-content { font-family: "Helvetica Neue", Arial, "Hiragino Sans GB", STHeit ...
- Linux下压缩工具gzip和归档工具tar及其实战shell应用
Linux下压缩工具gzip和归档工具tar及其实战shell应用 第一章:gzip的使用技巧 gzip [option]... file... -d: 解压缩,相当于gunzip; -# ...
- Linux文件压缩与打包笔记
linux 文件压缩与打包笔记 压缩原理:通过算法去掉空位,1Bytes=8bits , 可能存储的真正有用的数据并没有占满一个字节空间 , 还有就是可能有重复的数据,通过某种算法从这些方面进行压缩处 ...
- ubuntu下文件压缩/解压缩
ubuntu下文件压缩/解压缩 http://blog.csdn.net/luo86106/article/details/6946255 .gz 解压1:gunzip FileName.gz 解压2 ...
- Linux文件压缩和解压缩命令
Linux文件压缩和解压缩命令: tar 命令(打包并压缩的话,原文件也会默认存在) -c 建立打包档案 -x 解包 -t 查看包里的类容 -r 向包里追加文件 -v 显示打包过程 -f 文件 比如: ...
- 文件压缩、解压工具类。文件压缩格式为zip
package com.JUtils.file; import java.io.BufferedOutputStream; import java.io.File; import java.io.Fi ...
- linux文件压缩与文件夹压缩(打包)
目录 一:linux文件压缩 1.linux常见的压缩包有哪些? 2.bzip压缩(文件) 二:打包(文件夹压缩) 1.打包命令 2.参数 3.参数解析(实战) 4.注意事项 简介: win中的压缩包 ...
随机推荐
- boost graph
Boost Graph provides tools to work with graphs. Graphas are two-dimensional point clouds with any nu ...
- STM32时钟设置
一.使用外部时钟,并设置为72MHz void SetSysClockToHSE(void) { ErrorStatus HSEStartUpStatus; /* SYSCLK, HCLK, PCLK ...
- Alex and Number
Alex and Number 时间限制: 1 Sec 内存限制: 128 MB提交: 69 解决: 12[提交][状态] 题目描述 Alex love Number theory. Today ...
- 禅道安装--结合openldap
原文地址: https://blog.csdn.net/plei_yue/article/details/79075298 ldap结合禅道(需要神道不是开源版) https://www.cnblog ...
- spring boot 修改banner
在resources目录下新建一个banner.txt,里面添加要显示的内容,如: ////////////////////////////////////////////////////////// ...
- 颁发不受浏览器信任的SSL证书
xshell登录服务器,使用openssl生成RSA密钥及证书 # 生成一个RSA密钥 $ openssl genrsa -des3 -out tfjybj.key 1024 # 生成一个证书请求$ ...
- 移动H5优化指南
转载于http://isux.tencent.com/h5-performance.html 移动H5前端性能优化指南 概述 秒完成或使用Loading4. 基于联通3G网络平均338KB/s(2.7 ...
- Bootstrap 学习笔记3 路径分页标签和徽章组件
- C# 获取微信小程序access_token
/// <summary> /// 获取access_token /// </summary> /// <returns></returns> publ ...
- JS获取url多个参数及解决中文乱码问题
function GetQueryString(name) { var reg = new RegExp("(^|&)"+ name +"=([^&am ...