Linux Command gzip 压缩
  TEZNKK3IfmPf 2023年11月14日 27 0

Linux Command gzip 压缩

1. 说明

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

2. 安装

准备编译 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
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月14日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   2024年05月31日   52   0   0 linux服务器
  TEZNKK3IfmPf   2024年05月31日   31   0   0 linux服务器centos
  TEZNKK3IfmPf   2024年05月31日   29   0   0 linuxbind
  TEZNKK3IfmPf   2024年05月31日   40   0   0 linuxshell
TEZNKK3IfmPf