用途说明
compress命令是用来将文件压缩成.Z格式的,对应的uncompress是用来解压的。Compress reduces the size of the named files using adaptive Lempel-Zivcoding. Whenever possible, each file is replaced by one with theextension .Z, while keeping the same ownership modes, access andmodification times.
这个命令使用的算法因为不够先进,在Linux下现在都采用gzip和gunzip来压缩和解压了。但是很多老的压缩文件可能是.z格式的,因此需要用到它。一般情况下,安装好的Linux系统下可能没有这个命令,那么就需要到安装盘中找到包含 ncompress字符串的rpm包来进行安装。这也是网上很多人问“在LINUX 中没有COMPRESS这个命令”或“为什么linux中的compress不能用”的原因了。
常用参数
因为compress和uncompress并不常用,因此参数并不太重要了,在需要时man一下就清楚了。
使用示例
示例一 压缩文件
[root@localhost ~]# ls -l install.log
-rw-r--r-- 1 root root 48038 10月 8 17:18 install.log
[root@localhost ~]# compress install.log
[root@localhost ~]# ls -l install.log install.log.Z
ls: install.log:没有那个文件或目录
-rw-r--r-- 1 root root 17034 10月 8 17:18 install.log.Z
[root@localhost ~]#
示例二 解压.Z文件
[root@localhost ss7linux]# uncompress dpklnx6.Z
-bash: uncompress: command not found
[root@localhost ss7linux]# cd /software/
[root@localhost software]# ls
disc1 disc2 disc3 disc4 ss7
[root@localhost software]# find . -name "ncompress*"
./disc4/RedHat/RPMS/ncompress-4.2.4-40.i386.rpm
[root@localhost software]# rpm -ivh ./disc4/RedHat/RPMS/ncompress-4.2.4-40.i386.rpm
warning: ./disc4/RedHat/RPMS/ncompress-4.2.4-40.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing... ########################################### [100%]
1:ncompress ########################################### [100%]
[root@localhost software]# cd /root/setup/ss7linux/
[root@localhost ss7linux]# uncompress dpklnx6.Z
[root@localhost ss7linux]# ls
dpklnx6
示例三 在CentOS4.8下安装ncompress
CentOS4.8的ncompress包在第四章光盘中。
[root@localhostmedia]# pwd
/media
[root@localhostmedia]# mount /dev/cdrom
mount: block device/dev/hdc is write-protected, mounting read-only
[root@localhostmedia]# cd cdrom/
[root@localhostcdrom]# find . -name "ncompress*.rpm"
./CentOS/RPMS/ncompress-4.2.4-44.rhel4.i386.rpm
[root@localhostcdrom]# rpm -ivh./CentOS/RPMS/ncompress-4.2.4-44.rhel4.i386.rpm
警告:./CentOS/RPMS/ncompress-4.2.4-44.rhel4.i386.rpm:V3 DSA 簽章:NOKEY, key ID 443e1821
準備中... ########################################### [100%]
1:ncompress ########################################### [100%]
[root@localhostcdrom]# cd ..
[root@localhostmedia]# umount /dev/cdrom