---
title: "我使用过的Linux命令之uncompress - 解压.Z文件"
author: "codingstandards"
date: "2010-10-21T20:43:58Z"
tags: ["Bash", "CentOS", "Linux", "RedHat", "算法"]
categories: ["操作系统"]
slug: "linux-uncompress-z"
draft: false
lastmod: "2010-10-25T17:43:15Z"
id: 790830
url: "https://codingstandards.iteye.com/blog/790830"
---

# 我使用过的Linux命令之uncompress - 解压.Z文件

本文链接：[http://codingstandards.iteye.com/blog/790830](/blog/790830)    （转载请注明出处）

## 用途说明

compress命令是用来将文件压缩成.Z格式的，对应的uncompress是用来解压的。Compress  reduces  the size of the named files using adaptive Lempel-Ziv coding.  Whenever possible, each file is replaced by one with the extension .Z, while keeping the same ownership modes, access and modification  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 

&lt;!-- \[if gte mso 9]&gt;&lt;xml&gt;&lt;w:WordDocument&gt;&lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;&lt;w:DisplayHorizontalDrawingGridEvery&gt;0&lt;/w:DisplayHorizontalDrawingGridEvery&gt;&lt;w:DisplayVerticalDrawingGridEvery&gt;2&lt;/w:DisplayVerticalDrawingGridEvery&gt;&lt;w:DocumentKind&gt;DocumentNotSpecified&lt;/w:DocumentKind&gt;&lt;w:DrawingGridVerticalSpacing&gt;7.8&lt;/w:DrawingGridVerticalSpacing&gt;&lt;w:View&gt;Normal&lt;/w:View&gt;&lt;w:Compatibility&gt;&lt;/w:Compatibility&gt;&lt;w:Zoom&gt;0&lt;/w:Zoom&gt;&lt;/w:WordDocument&gt;&lt;/xml&gt;&lt;!\[endif]--&gt;

\[root@localhost ss7linux]# ls

dpklnx6

 

### 示例三 在CentOS4.8下安装ncompress

CentOS4.8的ncompress包在第四章光盘中。

\[root@localhost media]# pwd  
/media

\[root@localhost media]# mount /dev/cdrom  
mount: block device /dev/hdc is write-protected, mounting read-only  
\[root@localhost media]# cd cdrom/  
\[root@localhost cdrom]# find . -name "ncompress\*.rpm"  
./CentOS/RPMS/ncompress-4.2.4-44.rhel4.i386.rpm  
\[root@localhost cdrom]# 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@localhost cdrom]# cd ..  
\[root@localhost media]# umount /dev/cdrom

## 问题思考

1\. compress和uncompress使用的压缩算法的大体原理如何？

2\. 是比较各种压缩工具（compress、gzip、bzip2、tar、rar等）的效率、压缩比率？

## 相关资料

【1】中国IT实验室 [Linux 指令篇:编码压缩打包--compress](http://linux.chinaitlab.com/command/11562.html)

【2】鳥哥的 Linux 私房菜  [第九章、檔案與檔案系統的壓縮與打包](http://linux.vbird.org/linux_basic/0240tarcompress.php#compress)

 

返回 [我使用过的Linux命令系列总目录](/blog/786653)