linux命令之gzip
1.gzip介绍
linux命令gzip是用来压缩文件的命令,文件压缩后,后缀名为".gz"
2.gzip用法
gzip [参数] filename
gzip常用参数
参数 |
说明 |
-d |
解压缩文件 |
-l |
列出压缩文件的信息 |
-r |
压缩递归处理 |
-t |
测试压缩文件是否正确 |
-v |
显示命令执行详细过程 |
-<压缩效率> |
压缩效率,值范围:1-9,值越大,压缩效率越高 |
--best |
等价于-9 |
--fast |
等价于-1 |
3.实例
3.1.压缩文件zzz.txt
命令:
gzip zzz.txt
[root@rhel77 ~]# gzip zzz.txt
[root@rhel77 ~]# ls -lrt zzz.txt.gz
-rw-r--r-- 1 root root 32 Jul 21 13:59 zzz.txt.gz
[root@rhel77 ~]# gzip -l zzz.txt.gz
compressed uncompressed ratio uncompressed_name
32 13 53.8% zzz.txt
[root@rhel77 ~]# gzip -t zzz.txt.gz
[root@rhel77 ~]#
3.2.递归压缩ztj目录下的文件
命令:
gzip -rv ztj/
[root@rhel77 ~]# gzip -rv ztj/
ztj//root.sh: 22.0% -- replaced with ztj//root.sh.gz
ztj//root-1.sh: 22.9% -- replaced with ztj//root-1.sh.gz
ztj//1.txt: 0.0% -- replaced with ztj//1.txt.gz
ztj//2.txt: 0.0% -- replaced with ztj//2.txt.gz
ztj//3.txt: 0.0% -- replaced with ztj//3.txt.gz
ztj//4.txt: 0.0% -- replaced with ztj//4.txt.gz
ztj//5.txt: 0.0% -- replaced with ztj//5.txt.gz
ztj//6.txt: 0.0% -- replaced with ztj//6.txt.gz
[root@rhel77 ~]# cd ztj
[root@rhel77 ztj]# ls
1.txt.gz 2.txt.gz 3.txt.gz 4.txt.gz 5.txt.gz 6.txt.gz root-1.sh.gz root.sh.gz test
[root@rhel77 ztj]#
3.3.解压缩ztj目录下的文件
命令:
gzip -rdv ztj/
[root@rhel77 ~]# gzip -rdv ztj/
ztj//root.sh.gz: 22.0% -- replaced with ztj//root.sh
ztj//root-1.sh.gz: 22.9% -- replaced with ztj//root-1.sh
ztj//1.txt.gz: 0.0% -- replaced with ztj//1.txt
ztj//2.txt.gz: 0.0% -- replaced with ztj//2.txt
ztj//3.txt.gz: 0.0% -- replaced with ztj//3.txt
ztj//4.txt.gz: 0.0% -- replaced with ztj//4.txt
ztj//5.txt.gz: 0.0% -- replaced with ztj//5.txt
ztj//6.txt.gz: 0.0% -- replaced with ztj//6.txt
[root@rhel77 ~]# cd ztj
[root@rhel77 ztj]# ls
1.txt 2.txt 3.txt 4.txt 5.txt 6.txt root-1.sh root.sh test
[root@rhel77 ztj]#
3.4.解压缩zzz.txt.gz文件
命令:
gzip -dv zzz.txt.gz
[root@rhel77 ~]# gzip -dv zzz.txt.gz
zzz.txt.gz: 53.8% -- replaced with zzz.txt
[root@rhel77 ~]# ls -l zzz.txt
-rw-r--r-- 1 root root 13 Jul 21 13:59 zzz.txt
[root@rhel77 ~]#