[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
[root@rhel6 test]# gzip -d ssh.gz
[root@rhel6 test]# ls
loo ssh ssh_config
[root@rhel6 test]# gzip -l ssh.gz
compressed uncompressed ratio uncompressed_name
1034 2047 50.6% ssh
[root@rhel6 test]# ls -R loo/
loo/:
ab abc lo
abcd
[root@rhel6 test]# gzip -r loo/
[root@rhel6 test]# ls -R loo/
loo/:
abc.gz ab.gz lo
abcd.gz
[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一样的效果。
-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
[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
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%!