linux命令--gzip

来源:互联网 发布:用python搭建知识图谱 编辑:程序博客网 时间:2024/05/16 10:11

功能说明

gzip命令用来压缩文件。gzip是个使用广泛的压缩程序,文件经它压缩过后,其名称后面会多处“.gz”扩展名。 gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用。gzip不仅可以用来压缩大的、较少使用的文件以节省磁盘空间,还可以和tar命令一起构成Linux操作系统中比较流行的压缩文件格式。据统计,gzip命令对文本文件有60%~70%的压缩率。减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间。

常用选项

1.命令格式:

gzip[参数][文件或者目录]

2.命令功能:

gzip是个使用广泛的压缩程序,文件经它压缩过后,其名称后面会多出”.gz”的扩展名。

3.命令参数:

-a或–ascii  使用ASCII文字模式。

-c或–stdout或–to-stdout  把压缩后的文件输出到标准输出设备,不去更动原始文件。

-d或–decompress或—-uncompress  解开压缩文件。

-f或–force  强行压缩文件。不理会文件名称或硬连接是否存在以及该文件是否为符号连接。

-h或–help  在线帮助。

-l或–list  列出压缩文件的相关信息。

-L或–license  显示版本与版权信息。

-n或–no-name  压缩文件时,不保存原来的文件名称及时间戳记。

-N或–name  压缩文件时,保存原来的文件名称及时间戳记。

-q或–quiet  不显示警告信息。

-r或–recursive  递归处理,将指定目录下的所有文件及子目录一并处理。

-S<压缩字尾字符串>或—-suffix<压缩字尾字符串>  更改压缩字尾字符串。

-t或–test  测试压缩文件是否正确无误。

-v或–verbose  显示指令执行过程。

-V或–version  显示版本信息。

-num 用指定的数字num调整压缩的速度,-1或–fast表示最快压缩方法(低压缩比),-9或–best表示最慢压缩方法(高压缩比)。系统缺省值为6。

使用实例

1.递归的压缩目录

scarlett@scarlett-X550VXK:~/file$ gzip -rv ././/5.txt:    75.5% -- replaced with .//5.txt.gz.//.profile:     42.3% -- replaced with .//.profile.gz.//22.txt:   69.8% -- replaced with .//22.txt.gz.//10.txt:   75.5% -- replaced with .//10.txt.gz.//20.txt:   70.6% -- replaced with .//20.txt.gz.//test/1.txt:    0.0% -- replaced with .//test/1.txt.gz.//16.txt:   74.1% -- replaced with .//16.txt.gz.//file.tar:     83.2% -- replaced with .//file.tar.gz.//24.txt:   76.9% -- replaced with .//24.txt.gz.//2.txt:    14.3% -- replaced with .//2.txt.gz.//1.txt:     0.0% -- replaced with .//1.txt.gz.//21.txt:   74.5% -- replaced with .//21.txt.gz.//23.txt:   76.1% -- replaced with .//23.txt.gz.//15.txt:   74.2% -- replaced with .//15.txt.gz.//file.tar.bz2:     -0.0% -- replaced with .//file.tar.bz2.gz

2.递归的解压目录

scarlett@scarlett-X550VXK:~/file$ gzip -drv ././/22.txt.gz:    69.8% -- replaced with .//22.txt.//10.txt.gz:    75.5% -- replaced with .//10.txt.//15.txt.gz:    74.2% -- replaced with .//15.txt.//1.txt.gz:      0.0% -- replaced with .//1.txt.//.profile.gz:  42.3% -- replaced with .//.profile.//file.tar.gz:  83.2% -- replaced with .//file.tar.//test/1.txt.gz:     0.0% -- replaced with .//test/1.txt.//2.txt.gz:     14.3% -- replaced with .//2.txt.//20.txt.gz:    70.6% -- replaced with .//20.txt.//16.txt.gz:    74.1% -- replaced with .//16.txt.//24.txt.gz:    76.9% -- replaced with .//24.txt.//23.txt.gz:    76.1% -- replaced with .//23.txt.//21.txt.gz:    74.5% -- replaced with .//21.txt.//5.txt.gz:     75.5% -- replaced with .//5.txt.//file.tar.bz2.gz:  -0.0% -- replaced with .//file.tar.bz2

3.压缩一个tar备份文件,此时压缩文件的扩展名为.tar.gz

scarlett@scarlett-X550VXK:~/file$ tar -cvf test.tar ./*.txt ./test/*./10.txt./15.txt./16.txt./1.txt./20.txt./21.txt./22.txt./23.txt./24.txt./2.txt./5.txt./test/1.txtscarlett@scarlett-X550VXK:~/file$ gzip test.tarscarlett@scarlett-X550VXK:~/file$ ls10.txt  16.txt  20.txt  22.txt  24.txt  5.txt     file.tar.bz2  test.tar.gz15.txt  1.txt   21.txt  23.txt  2.txt   file.tar  test
原创粉丝点击