linux命令之gzip命令详解和使用实例(2)
代码如下: [root@localhost test6]# gzip -l * compressed uncompressed ratio uncompressed_name 1341 302108 99.6% linklog.log 1341 302108 99.6% log2012.log 70 61 47.5% log2013.log 32 0 0.0% log2014.lo
代码如下:
[root@localhost test6]# gzip -l *
compressed uncompressed ratio uncompressed_name
1341 302108 99.6% linklog.log
1341 302108 99.6% log2012.log
70 61 47.5% log2013.log
32 0 0.0% log2014.log
32 0 0.0% log2015.log
32 0 0.0% log2016.log
32 0 0.0% log2017.log
2880 604277 99.5% (totals)
实例4:压缩一个tar备份文件,此时压缩文件的扩展名为.tar.gz
命令:
代码如下:
gzip -r log.tar
输出:
代码如下:
[root@localhost test]# ls -al log.tar
-rw-r--r-- 1 root root 307200 11-29 17:54 log.tar
[root@localhost test]# gzip -r log.tar
[root@localhost test]# ls -al log.tar.gz
-rw-r--r-- 1 root root 1421 11-29 17:54 log.tar.gz
实例5:递归的压缩目录
命令:
代码如下:
gzip -rv test6
输出:
代码如下:
[root@localhost test6]# ll
总计 604
---xr--r-- 1 root mail 302108 11-30 08:39 linklog.log
---xr--r-- 1 mail users 302108 11-30 08:39 log2012.log
-rw-r--r-- 1 mail users 61 11-30 08:39 log2013.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2014.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2015.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2016.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2017.log
[root@localhost test6]# cd ..
[root@localhost test]# gzip -rv test6
test6/log2014.log: 0.0% -- replaced with test6/log2014.log.gz
test6/linklog.log: 99.6% -- replaced with test6/linklog.log.gz
test6/log2015.log: 0.0% -- replaced with test6/log2015.log.gz
test6/log2013.log: 47.5% -- replaced with test6/log2013.log.gz
test6/log2012.log: 99.6% -- replaced with test6/log2012.log.gz
test6/log2017.log: 0.0% -- replaced with test6/log2017.log.gz
test6/log2016.log: 0.0% -- replaced with test6/log2016.log.gz
[root@localhost test]# cd test6
[root@localhost test6]# ll
总计 28
---xr--r-- 1 root mail 1341 11-30 08:39 linklog.log.gz
---xr--r-- 1 mail users 1341 11-30 08:39 log2012.log.gz
-rw-r--r-- 1 mail users 70 11-30 08:39 log2013.log.gz
-rw-r--r-- 1 root mail 32 11-30 08:39 log2014.log.gz
-rw-r--r-- 1 root mail 32 11-30 08:39 log2015.log.gz
-rw-r--r-- 1 root mail 32 11-30 08:39 log2016.log.gz
-rw-r--r-- 1 root mail 32 11-30 08:39 log2017.log.gz
说明:
这样,所有test下面的文件都变成了*.gz,目录依然存在只是目录里面的文件相应变成了*.gz.这就是压缩,和打包不同。因为是对目录操作,所以需要加上-r选项,这样也可以对子目录进行递归了。
实例6:递归地解压目录
命令:
代码如下:
gzip -dr test6
输出:
代码如下:
[root@localhost test6]# ll
总计 28
---xr--r-- 1 root mail 1341 11-30 08:39 linklog.log.gz
---xr--r-- 1 mail users 1341 11-30 08:39 log2012.log.gz
-rw-r--r-- 1 mail users 70 11-30 08:39 log2013.log.gz
-rw-r--r-- 1 root mail 32 11-30 08:39 log2014.log.gz
-rw-r--r-- 1 root mail 32 11-30 08:39 log2015.log.gz
-rw-r--r-- 1 root mail 32 11-30 08:39 log2016.log.gz
-rw-r--r-- 1 root mail 32 11-30 08:39 log2017.log.gz
[root@localhost test6]# cd ..
[root@localhost test]# gzip -dr test6
[root@localhost test]# cd test6
[root@localhost test6]# ll
总计 604
---xr--r-- 1 root mail 302108 11-30 08:39 linklog.log
---xr--r-- 1 mail users 302108 11-30 08:39 log2012.log
-rw-r--r-- 1 mail users 61 11-30 08:39 log2013.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2014.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2015.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2016.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2017.log
[root@localhost test6]#</p> <p>
精彩图集
精彩文章