centos安装compress压缩工具
压缩后的档案可以以 uncompress
解压。若要将数个档案压成一个压缩档,必须先将档案 tar
起来再压缩。由于 gzip
可以产生更理想的压缩比例,一般人多已改用 gzip
为档案压缩工具。
安装compress
[root@localhost ~]# yum -y install ncompress
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package ncompress.x86_64 0:4.2.4.4-3.1.el7_8 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================
Package Arch Version Repository Size
============================================================================
Installing:
ncompress x86_64 4.2.4.4-3.1.el7_8 base 27 k
Transaction Summary
============================================================================
Install 1 Package
Total download size: 27 k
Installed size: 35 k
Downloading packages:
ncompress-4.2.4.4-3.1.el7_8.x86_64.rpm | 27 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : ncompress-4.2.4.4-3.1.el7_8.x86_64 1/1
Verifying : ncompress-4.2.4.4-3.1.el7_8.x86_64 1/1
Installed:
ncompress.x86_64 0:4.2.4.4-3.1.el7_8
Complete!
[root@localhost ~]# compress -V #查看安装版本
ompress version: (N)compress 4.2.4.4, compiled: Tue Jun 23 15:37:14 UTC 2020
Compile options:
FAST, DIRENT,
REGISTERS=20 IBUFSIZ=8192, OBUFSIZ=1024, BITS=16
Author version 4.2 (Speed improvement & source cleanup):
Peter Jannesen (peter@ncs.nl)
Author version 4.1 (Added recursive directory compress):
Dave Mack (csu@alembic.acs.com)
Authors version 4.0 (World release in 1985):
Spencer W. Thomas, Jim McKie, Steve Davies,
Ken Turkowski, James A. Woods, Joe Orost
[root@localhost ~]# compress -h
Unknown flag: 'h'; Usage: compress [-dfvcVr] [-b maxbits] [file ...]
-d If given, decompression is done instead.
-c Write output on stdout, don't remove original.
-b Parameter limits the max number of bits/code.
-f Forces output file to be generated, even if one already.
exists, and even if no space is saved by compressing.
If -f is not used, the user will be prompted if stdin is.
a tty, otherwise, the output file will not be overwritten.
-v Write compression statistics.
-V Output vesion and compile options.
-r Recursive. If a filename is a directory, descend
into it and compress everything in it.
使用参数:
- c 输出结果至标准输出设备(一般指荧幕)
- f 强迫写入档案,若目的档已经存在,则会被覆盖 (force)
- v 将程序执行的讯息印在荧幕上 (verbose)
- b 设定共同字串数的上限,以位元计算,可以设定的值为 9 至 16 bits 。由于值越大,能使用的共同字串就 越多,压缩比例就越大,所以一般使用预设值 16 bits (bits)
- d 将压缩档解压缩
- V 列出版本讯息
- r 递归压缩目录下所有文件
压缩文件
将
a.txt
压缩为a.txt.Z
文件
[root@localhost ~]# ls
a.txt
[root@localhost ~]# compress -f a.txt
[root@localhost ~]# ls
a.txt.Z
解压文件
将刚压缩的文件解压
[root@localhost ~]# ls
a.txt.Z
[root@localhost ~]# compress -d a.txt.Z
[root@localhost ~]# ls
a.txt
压缩目录下的文件
强制递归压缩目录使用
-r
递归-f
压缩文件
[root@localhost ~]# ls
a.txt
[root@localhost ~]# compress -rf /root/a.txt
[root@localhost ~]# ls
a.txt.Z