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的命令使用情况。

 

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


目录
相关文章
|
3天前
|
安全 Linux
Linux系统之lsof命令的基本使用
【10月更文挑战第14天】Linux系统之lsof命令的基本使用
25 2
Linux系统之lsof命令的基本使用
|
4天前
|
前端开发 Unix Linux
揭秘 Electron 的 Linux 打包过程:你知道背后发生了什么吗?
本文详细介绍了 `electron-builder` 在 Linux 平台上如何打包 Electron 应用程序,涵盖了 AppImage、Flatpak、Snap 等多种格式的打包原理和具体实现。文章从初始化 `LinuxPackager` 到创建各种目标格式的包,详细解析了每个步骤的代码逻辑和关键方法,帮助开发者更好地理解和使用 `electron-builder` 进行 Linux 应用的打包。
19 2
揭秘 Electron 的 Linux 打包过程:你知道背后发生了什么吗?
|
5天前
|
Linux
Linux 系统五种帮助命令的使用
Linux 系统五种帮助命令的使用
31 14
|
1天前
|
运维 网络协议 Linux
linux系统命令 losf详解
**lsof命令**(List Open Files)是Linux系统中一个非常实用的工具,用于列出当前系统上所有打开的文件以及与之关联的进程。以下是对lsof命令的详细介绍: ### 一、基本功能 lsof命令可以显示系统中被进程打开的文件,这些文件可以是普通文件、目录、网络套接字、设备文件等。通过lsof命令,用户可以方便地查看哪些文件被哪些进程打开,以及这些文件的状态信息。 ### 二、基本语法 lsof命令的基本语法为:`lsof [选项] [文件]`。其中,选项用于指定lsof命令的行为,文件则是可选的,用于指定要查询的文件。 ### 三、常用选项 * `-a` 或 `-
|
1天前
|
Linux Perl
Linux awk命令使用技巧
【10月更文挑战第16天】Linux awk命令使用技巧
9 4
|
6天前
|
Linux
Linux经常使用命令汇总和总结
Linux经常使用命令汇总和总结
25 1
|
6天前
|
安全 Linux Shell
Linux | Rsync 命令:16 个实际示例(上)
Linux | Rsync 命令:16 个实际示例(上)
20 0
Linux | Rsync 命令:16 个实际示例(上)
|
9天前
|
存储 安全 Linux
Linux文件管理命令md5sum awk
通过结合 `md5sum`和 `awk`,不仅可以高效地进行文件完整性校验,还能灵活地处理和分析校验结果,为系统管理、数据审计等工作提供强大的支持。
20 2
|
10天前
|
运维 Java Linux
Linux 下命令后台运行秘籍:无惧终端断开的魔法
本文详细介绍了在 Linux 系统下使命令不受终端断开影响、持续在后台运行的多种方法及其原理。包括使用 `nohup`、`setsid`、括号括起来、作业调度和 `screen` 等技巧,帮助读者提高工作效率,确保任务不被意外中断。
40 0
Linux 下命令后台运行秘籍:无惧终端断开的魔法
|
5天前
|
Unix Linux 开发工具
Linux Vim的 命令大全
Linux Vim的 命令大全
12 0