Linux Command gzip 压缩

Linux Command gzip 压缩

1. 简介

gzip 命令作用不能是目录,只能压缩单个文件。

2. 安装

下载 gzip

准备编译 Gzip:

./configure --prefix=/usr --bindir=/bin
编译软件包:

make
用以下命令测试结果:

make check
安装软件包:

make install
移动不需要在根文件系统的程序:

mv -v /bin/{gzexe,uncompress,zcmp,zdiff,zegrep} /usr/bin
mv -v /bin/{zfgrep,zforce,zgrep,zless,zmore,znew} /usr/bin

3. 格式

gunzip [-acfhlLnNqrtvV][-s ][文件...]

或者gunzip [-acfhlLnNqrtvV][-s ][目录]

4. 参数

-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:显示版本信息。

5. 举例

1.Linux压缩保留源文件的方法:

gzip -c filename > filename.gz

2.Linux解压缩保留源文件的方法:

gunzip -c filename.gz > filename

3.把多文件不保留源文件压缩成.gz文件

$ ls
01.txt  02.txt  03.txt  04.txt  05.txt  06.txt  
$ gzip *
$ ls
01.txt.gz  02.txt.gz  03.txt.gz  04.txt.gz  05.txt.gz  06.txt.gz 

4.详细显示每个压缩的文件的信息,并不解压

$ gzip -l *
         compressed        uncompressed  ratio uncompressed_name
                 26                   0   0.0% 1.txt
                 26                   0   0.0% 2.txt
                 26                   0   0.0% 3.txt
                 26                   0   0.0% 4.txt
                 26                   0   0.0% 5.txt
                 26                   0   0.0% 6.txt

5.每个压缩的文件解压,并列出详细的信息

$ gzip -dv *
01.txt.gz:        0.0% -- replaced with 01.txt
02.txt.gz:        0.0% -- replaced with 02.txt
03.txt.gz:        0.0% -- replaced with 03.txt
04.txt.gz:        0.0% -- replaced with 04.txt
05.txt.gz:        0.0% -- replaced with 05.txt
06.txt.gz:        0.0% -- replaced with 06.txt
$ ls
01.txt  02.txt  03.txt  04.txt  05.txt  06.txt  

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

$ ls log.tar
 log.tar
$ gzip -r log.tar
$ ls
 log.tar.gz

7.递归的压缩目录

$  ls
1.txt  2.txt  3.txt  4.txt  5.txt  6.txt
$ cd ..
$ gzip -rv dir1/
dir1//1.txt:	  0.0% -- replaced with dir1//1.txt.gz
dir1//2.txt:	  0.0% -- replaced with dir1//2.txt.gz
dir1//3.txt:	  0.0% -- replaced with dir1//3.txt.gz
dir1//4.txt:	  0.0% -- replaced with dir1//4.txt.gz
dir1//5.txt:	  0.0% -- replaced with dir1//5.txt.gz
dir1//6.txt:	  0.0% -- replaced with dir1//6.txt.gz
$ ls dir1/
1.txt.gz  2.txt.gz  3.txt.gz  4.txt.gz  5.txt.gz  6.txt.gz

8.递归地解压目录

$ gzip -dr dir1/
$ ls dir1/
1.txt  2.txt  3.txt  4.txt  5.txt  6.txt

更多阅读:

  1. Linux Command lz4 压缩
  2. Linux Command tar 压缩
  3. Linux Command gzip 压缩
  4. Linux Command zip 压缩

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ghostwritten

口渴,请赏一杯下午茶吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值