gzip 压缩命令。默认执行gzip就是压缩文件,且删除原文件。gunzip就是解压文件。zcat查看压缩文件里面文档的内容。

-c 输出压缩的文件,并且保持原文件。注意,要在-c后面将输出的文件输入到指定的文件才行,不然会在屏幕上显示一堆的乱码!如:
[root@rhel6 test]# ls
loo  ssh_config
[root@rhel6 test]# gzip -c ssh_config >ssh.gz
[root@rhel6 test]# ls
loo  ssh_config  ssh.gz

-d 解压文件
[root@rhel6 test]# gzip -d ssh.gz
[root@rhel6 test]# ls
loo  ssh  ssh_config
 

-l 列出压缩文件内容
[root@rhel6 test]# gzip -l ssh.gz
         compressed        uncompressed  ratio uncompressed_name
               1034                2047  50.6% ssh
 

-r递归压缩,压缩文件夹及文件夹里面的所有文档。
[root@rhel6 test]# ls -R loo/
loo/:
ab  abc  lo

loo/lo:
abcd
[root@rhel6 test]# gzip -r loo/
[root@rhel6 test]# ls -R loo/
loo/:
abc.gz  ab.gz  lo

loo/lo:
abcd.gz
 

-v对文件进行压缩且显示每个文件的压缩率。不能对已经压缩了的文件生效。
[root@rhel6 test]# ll ssh_config
-rw-r--r--. 1 root root 2047 11月 11 00:29 ssh_config
[root@rhel6 test]# gzip -v ssh_config
ssh_config:      50.6% -- replaced with ssh_config.gz
[root@rhel6 test]# ll ssh_config.gz
-rw-r--r--. 1 root root 1041 11月 11 00:29 ssh_config.gz

zcat可以查看压缩文件里面文档的内容,但不是列出压缩文件的列表哦!用-l可以列出压缩文件中文件列表。
[root@rhel6 test]# echo aa >test
[root@rhel6 test]# gzip test
[root@rhel6 test]# zcat test.gz
aa
即相当于我们对普通文件cat test一样的效果。

bzip2 算是gzip的替代者吧。效果要强于gzip。但bzip2并不能解压gz的文件。两者并不兼容。同样,默认bzip2为压缩。bunzip2为解压。bzcat为查看压缩文件内文件的内容。
-d 解压,与gzip一样
-z 压缩
-k 保持原文件压缩或解压
-f 覆盖已存在的同名文件,与gzip一样
-t 测试压缩文件,与gzip一样
-c 标准输出,与gzip一样
-q安静模式,即不显示错误信息,与gzip一样
-v 显示详细信息并压缩,与gzip一样。
-s 以小内存模式运行,即不怎么占用内存。
[root@rhel6 test]# ls
loo  ssh  ssh_config  test
[root@rhel6 test]# bzip2 ssh                ------压缩,不保存原文档
[root@rhel6 test]# ls
loo  ssh.bz2  ssh_config  test
[root@rhel6 test]# bzip2 -d ssh.bz2               -----------解压缩,不保存压缩档
[root@rhel6 test]# ls
loo  ssh  ssh_config  test
[root@rhel6 test]# bzip2 -k ssh                 ----------压缩,保存原文档
[root@rhel6 test]# ls
loo  ssh  ssh.bz2  ssh_config  test
[root@rhel6 test]# bunzip2 ssh.bz2               -----------解压缩,由于原文件存在,则报错
bunzip2: Output file ssh already exists.
[root@rhel6 test]# bunzip2 -f ssh.bz2             ----------强制覆盖同名文件
[root@rhel6 test]# ls
loo  ssh  ssh_config  test
[root@rhel6 test]# bzip2 -z ssh            ------压缩
[root@rhel6 test]# bzip2 -d -q ssh.bz2           -------解压缩,不提示错误
[root@rhel6 test]# ls
loo  ssh  ssh_config  test
[root@rhel6 test]# bzip2 -v ssh             -----压缩,且显示详细停止
  ssh:      1.824:1,  4.385 bits/byte, 45.19% saved, 2047 in, 1122 out.
[root@rhel6 test]# ls
loo  ssh.bz2  ssh_config  test
 

bzip2与gzip压缩效率的比较
[root@rhel6 test]# gzip -c libgail.a >gzip.gz
[root@rhel6 test]# bzip2 -c libgail.a >bzip.bz2
[root@rhel6 test]# ll -h
总用量 5.9M
-rw-r--r--. 1 root root 948K 11月 11 12:00 bzip.bz2
-rw-r--r--. 1 root root 1.2M 11月 11 11:59 gzip.gz
-r--r--r--. 1 root root 2.9M 11月 11 11:58 libgail.a

由上可以看到,bzip2的压缩效率比gzip要好。具体好了多少呢?下面来验证下。

[root@rhel6 test]# gzip -c -v libgail.a >gzipv.gz
libgail.a:       60.5%
[root@rhel6 test]# bzip2 -c -v libgail.a >bzipv.bz2
  libgail.a:  3.056:1,  2.618 bits/byte, 67.28% saved, 2963820 in, 969825 out.
[root@rhel6 test]# ll bzipv.bz2 gzipv.gz libgail.a
-rw-r--r--. 1 root root  969825 11月 11 12:04 bzipv.bz2
-rw-r--r--. 1 root root 1169782 11月 11 12:04 gzipv.gz
-r--r--r--. 1 root root 2963820 11月 11 11:58 libgail.a
这里gzip的60.5%是(2963820-1169782)/2963820=60.5%而来的,同样,bzip2的67.28%也是这样计算来的。也就是说,这个60.5%的意思是一共节省了60.5%的空间!那么,很显然,bzip2节省得更多,为就是67.28%!

不管gz,还是bz2,这些在windows底下都是浮云!好压已经可以打开很多linux下面常见的压缩文件!至于winrar支持不支持暂不清楚,我比较支持国产!

相反的,如果要在linux下解压.rar的文件,那么就得安装rarlinux软件包才行。下载地址为http://www.rarlab.com/download.htm。在里面找到对应的就行了。具体使用方法我在前一篇已经写过了。