linux(二十六)打包压缩命令gzip

简介: linux(二十六)打包压缩命令gzip

Linux中第二个常用的解压缩命令gzip。

 

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

 

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

 

Gzip并不能压缩目录。只能压缩文件

 

1:参数选项


-a或——ascii:使用ASCII文字模式;


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


-<压缩效率>:压缩效率是一个介于1~9的数值,预设值为“6”,指定愈大的数值,压缩效率就会愈高;


--best:此参数的效果和指定“-9”参数相同;


--fast:此参数的效果和指定“-1”参数相同。

 

2:实例


(1):把当前目录下的每个文件压缩成.gz文件

[root@iZuf60ynur81p6k0ysvtneZ opt]# gzip *
gzip: a is a directory -- ignored
gzip: auth is a directory -- ignored
gzip: cp is a directory -- ignored
gzip: first is a directory -- ignored
gzip: mv is a directory -- ignored
gzip: second is a directory -- ignored
gzip: third is a directory -- ignored
[root@iZuf60ynur81p6k0ysvtneZ opt]# ll
total 64
-rw-r--r-- 1 root root   31 Aug 27 14:22 123466.txt.gz
-rwx------ 1 root root  101 Aug 27 18:02 123.txt.gz
-rw-r--r-- 1 root root   24 Aug 27 11:32 2.h.gz
-rw-r--r-- 1 root root   24 Aug 27 11:32 3.c.gz
drwxr-xr-x 3 root root 4096 Aug 27 11:17 a
drwx------ 2 root root 4096 Aug 27 10:49 auth
drwxr-xr-x 2 root root 4096 Aug 27 14:20 cp
-rwxrwxrwx 1 root test   71 Aug 28 11:33 echo.sh.gz
drwxr-xr-x 2 root root 4096 Sep 10 14:50 first
-rw-r--r-- 1 root root  286 Aug 28 11:55 menu.txt.gz
-rw-r--r-- 1 root root   50 Aug 28 11:55 m.gz
drwxr-xr-x 3 root root 4096 Sep  1 10:18 mv
drwxr-xr-x 2 root root 4096 Aug 27 10:48 second
-rw-r--r-- 1 root root  135 Aug 28 10:05 test.txt.gz
drwxr-xr-x 2 root root 4096 Aug 27 10:48 third
-rw-r--r-- 1 root root  290 Aug 28 10:20 total.txt.gz

(2):把上例中每个压缩的文件解压,并列出详细的信息

[root@iZuf60ynur81p6k0ysvtneZ opt]# gzip -dv *
123466.txt.gz:   0.0% -- replaced with 123466.txt
123.txt.gz:        26.5% -- replaced with 123.txt
2.h.gz:       0.0% -- replaced with 2.h
3.c.gz:       0.0% -- replaced with 3.c
gzip: a is a directory -- ignored
gzip: auth is a directory -- ignored
gzip: cp is a directory -- ignored
echo.sh.gz:       4.3% -- replaced with echo.sh
gzip: first is a directory -- ignored
menu.txt.gz:    65.2% -- replaced with menu.txt
m.gz:      -20.0% -- replaced with m
gzip: mv is a directory -- ignored
gzip: second is a directory -- ignored
test.txt.gz:        27.0% -- replaced with test.txt
gzip: third is a directory -- ignored
total.txt.gz:      35.6% -- replaced with total.txt
[root@iZuf60ynur81p6k0ysvtneZ opt]# ll
total 52
-rw-r--r-- 1 root root    0 Aug 27 14:22 123466.txt
-rwx------ 1 root root  102 Aug 27 18:02 123.txt
-rw-r--r-- 1 root root    0 Aug 27 11:32 2.h
-rw-r--r-- 1 root root    0 Aug 27 11:32 3.c
drwxr-xr-x 3 root root 4096 Aug 27 11:17 a
drwx------ 2 root root 4096 Aug 27 10:49 auth
drwxr-xr-x 2 root root 4096 Aug 27 14:20 cp
-rwxrwxrwx 1 root test   47 Aug 28 11:33 echo.sh
drwxr-xr-x 2 root root 4096 Sep 10 14:50 first
-rw-r--r-- 1 root root   25 Aug 28 11:55 m
-rw-r--r-- 1 root root  744 Aug 28 11:55 menu.txt
drwxr-xr-x 3 root root 4096 Sep  1 10:18 mv
drwxr-xr-x 2 root root 4096 Aug 27 10:48 second
-rw-r--r-- 1 root root  148 Aug 28 10:05 test.txt
drwxr-xr-x 2 root root 4096 Aug 27 10:48 third
-rw-r--r-- 1 root root  407 Aug 28 10:20 total.txt

 

(3):详细显示例1中每个压缩的文件的信息,并不解压

[root@iZuf60ynur81p6k0ysvtneZ opt]# gzip -l
^Z
[4]+  Stopped                 gzip -l
[root@iZuf60ynur81p6k0ysvtneZ opt]# gzip -l *
         compressed        uncompressed  ratio uncompressed_name
                 31                   0   0.0% 123466.txt
                101                 102  26.5% 123.txt
                 24                   0   0.0% 2.h
                 24                   0   0.0% 3.c
gzip: a is a directory -- ignored
gzip: auth is a directory -- ignored
gzip: cp is a directory -- ignored
                 71                  47   4.3% echo.sh
gzip: first is a directory -- ignored
                286                 744  65.2% menu.txt
                 50                  25 -20.0% m
gzip: mv is a directory -- ignored
gzip: second is a directory -- ignored
                135                 148  27.0% test.txt
gzip: third is a directory -- ignored
                290                 407  35.6% total.txt
               1012                1473  33.2% (totals)

 

(4):压缩一个tar备份文件,此时压缩文件的扩展名为.tar.gz

gzip -r echo.tar
[root@iZuf60ynur81p6k0ysvtneZ first]# ll
total 8
-rwxrwxrwx 1 root test  47 Aug 28 11:33 echo.sh
-rw-r--r-- 1 root root 163 Sep 10 14:27 echo.tar
[root@iZuf60ynur81p6k0ysvtneZ first]# gzip -r echo.tar
[root@iZuf60ynur81p6k0ysvtneZ first]# ll
total 8
-rwxrwxrwx 1 root test  47 Aug 28 11:33 echo.sh
-rw-r--r-- 1 root root 189 Sep 10 14:27 echo.tar.gz

 

 

(5):递归的压缩目录

gzip -rv first

 

(6):递归地解压目录

gzip -dr first

 

以上基本上就是gzip的命令使用情况。

 

有好的建议,请在下方输入你的评论。


目录
相关文章
|
6天前
|
Linux
Linux系统之whereis命令的基本使用
Linux系统之whereis命令的基本使用
50 23
Linux系统之whereis命令的基本使用
|
20天前
|
网络协议 Unix Linux
深入解析:Linux网络配置工具ifconfig与ip命令的全面对比
虽然 `ifconfig`作为一个经典的网络配置工具,简单易用,但其功能已经不能满足现代网络配置的需求。相比之下,`ip`命令不仅功能全面,而且提供了一致且简洁的语法,适用于各种网络配置场景。因此,在实际使用中,推荐逐步过渡到 `ip`命令,以更好地适应现代网络管理需求。
33 11
|
2月前
|
Linux Shell
Linux 10 个“who”命令示例
Linux 10 个“who”命令示例
99 14
Linux 10 个“who”命令示例
|
2月前
|
Ubuntu Linux
Linux 各发行版安装 ping 命令指南
如何在不同 Linux 发行版(Ubuntu/Debian、CentOS/RHEL/Fedora、Arch Linux、openSUSE、Alpine Linux)上安装 `ping` 命令,详细列出各发行版的安装步骤和验证方法,帮助系统管理员和网络工程师快速排查网络问题。
203 20
|
2月前
|
Linux
linux查看目录下的文件夹命令,find查找某个目录,但是不包括这个目录本身?
通过本文的介绍,您应该对如何在 Linux 系统中查看目录下的文件夹以及使用 `find` 命令查找特定目录内容并排除该目录本身有了清晰的理解。掌握这些命令和技巧,可以大大提高日常文件管理和查找操作的效率。 在实际应用中,灵活使用这些命令和参数,可以帮助您快速定位和管理文件和目录,满足各种复杂的文件系统操作需求。
140 8
|
2月前
|
网络协议 Linux 应用服务中间件
kali的常用命令汇总Linux
kali的常用命令汇总linux
128 7
|
3月前
|
Linux 数据库
Linux中第一次使用locate命令报错?????
在Linux CentOS7系统中,使用`locate`命令时出现“command not found”错误,原因是缺少`mlocate`包。解决方法是通过`yum install mlocate -y`或`apt-get install mlocate`安装该包,并执行`updatedb`更新数据库以解决后续的“can not stat”错误。
61 9
|
3月前
|
监控 网络协议 Linux
Linux netstat 命令详解
Linux netstat 命令详解
|
3月前
|
运维 监控 网络协议
运维工程师日常工作中最常用的20个Linux命令,涵盖文件操作、目录管理、权限设置、系统监控等方面
本文介绍了运维工程师日常工作中最常用的20个Linux命令,涵盖文件操作、目录管理、权限设置、系统监控等方面,旨在帮助读者提高工作效率。从基本的文件查看与编辑,到高级的网络配置与安全管理,这些命令是运维工作中的必备工具。
288 3
|
3月前
|
Linux
在 Linux 系统中,`find` 命令
在 Linux 系统中,`find` 命令
57 1