gzip:压缩或解压文件
简介gzip命令用于将一个大的文件通过压缩算法变成一个小的文件。gzip不能直接压缩目录,因此目录需要tar进行打包成一个文件,然后tar再调用gzip进行压缩。
说明
gzip命令用于将一个大的文件通过压缩算法变成一个小的文件。gzip不能直接压缩目录,因此目录需要tar进行打包成一个文件,然后tar再调用gzip进行压缩。
注意:gzip压缩后,源文件将会被删除,解压后,压缩文件也会被删除。
格式
gzip [option] [file]
常用参数
- -d:解开压缩文件
- -v:显示执行的过程
- -l:不解压列出压缩文件的内容信息
- -c:将内容输出到标准输出,不改变原始文件
- -r:对目录下的所有文件递归进行压缩操作
- -数字[1-9]:指定压缩率,默认为6,值越大压缩率越高
- -t:测试,检查压缩文件是否完整
示例
1、压缩所有的.txt文件
[root@localhost test]# ll
total 4
-rw-r----x. 1 root root 11 May 7 22:45 test_01.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_02.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_03.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_04.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_05.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_06.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_07.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_08.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_09.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_10.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_11.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_12.txt
-rw-r--r--. 1 root root 0 May 6 07:24 test.txt
[root@localhost test]# gzip *.txt
[root@localhost test]# ll #压缩后,源文件被删除了
total 52
-rw-r----x. 1 root root 43 May 7 22:45 test_01.txt.gz
-rw-r--r--. 1 root root 32 May 6 07:22 test_02.txt.gz
-rw-r--r--. 1 root root 32 May 6 07:22 test_03.txt.gz
-rw-r--r--. 1 root root 32 May 6 07:22 test_04.txt.gz
-rw-r--r--. 1 root root 32 May 6 07:22 test_05.txt.gz
-rw-r--r--. 1 root root 32 May 6 07:22 test_06.txt.gz
-rw-r--r--. 1 root root 32 May 6 07:22 test_07.txt.gz
-rw-r--r--. 1 root root 32 May 6 07:22 test_08.txt.gz
-rw-r--r--. 1 root root 32 May 6 07:22 test_09.txt.gz
-rw-r--r--. 1 root root 32 May 6 07:22 test_10.txt.gz
-rw-r--r--. 1 root root 32 May 6 07:22 test_11.txt.gz
-rw-r--r--. 1 root root 32 May 6 07:22 test_12.txt.gz
-rw-r--r--. 1 root root 29 May 6 07:24 test.txt.gz
2、不解压显示压缩文件的信息
[root@localhost test]# gzip -l *.txt.gz
compressed uncompressed ratio uncompressed_name
43 11 -18.2% test_01.txt
32 0 0.0% test_02.txt
32 0 0.0% test_03.txt
32 0 0.0% test_04.txt
32 0 0.0% test_05.txt
32 0 0.0% test_06.txt
32 0 0.0% test_07.txt
32 0 0.0% test_08.txt
32 0 0.0% test_09.txt
32 0 0.0% test_10.txt
32 0 0.0% test_11.txt
32 0 0.0% test_12.txt
29 0 0.0% test.txt
424 11 -3509.1% (totals)
3、解压文件,并显示解压的过程
[root@localhost test]# gzip -dv *.txt.gz
test_01.txt.gz: -18.2% -- replaced with test_01.txt
test_02.txt.gz: 0.0% -- replaced with test_02.txt
test_03.txt.gz: 0.0% -- replaced with test_03.txt
test_04.txt.gz: 0.0% -- replaced with test_04.txt
test_05.txt.gz: 0.0% -- replaced with test_05.txt
test_06.txt.gz: 0.0% -- replaced with test_06.txt
test_07.txt.gz: 0.0% -- replaced with test_07.txt
test_08.txt.gz: 0.0% -- replaced with test_08.txt
test_09.txt.gz: 0.0% -- replaced with test_09.txt
test_10.txt.gz: 0.0% -- replaced with test_10.txt
test_11.txt.gz: 0.0% -- replaced with test_11.txt
test_12.txt.gz: 0.0% -- replaced with test_12.txt
test.txt.gz: 0.0% -- replaced with test.txt
[root@localhost test]# ll #源压缩文件被删除了
total 4
-rw-r----x. 1 root root 11 May 7 22:45 test_01.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_02.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_03.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_04.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_05.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_06.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_07.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_08.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_09.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_10.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_11.txt
-rw-r--r--. 1 root root 0 May 6 07:22 test_12.txt
-rw-r--r--. 1 root root 0 May 6 07:24 test.txt
4、压缩解压保留源文件(单文件压缩,使用不方便)
[root@localhost test]# cp /etc/services .
[root@localhost test]# ll -h services
-rw-r--r--. 1 root root 655K May 14 15:17 services
[root@localhost test]# gzip -c services > services.gz #使用-c参数
[root@localhost test]# ll -h services*
-rw-r--r--. 1 root root 655K May 14 15:17 services
-rw-r--r--. 1 root root 133K May 14 15:17 services.gz
[root@localhost test]# gzip -dc services.gz > services2
[root@localhost test]# ll -h services*
-rw-r--r--. 1 root root 655K May 14 15:17 services
-rw-r--r--. 1 root root 655K May 14 15:17 services2
-rw-r--r--. 1 root root 133K May 14 15:17 services.gz
[root@localhost test]# diff services services2
gzip压缩和解压文件不能保存源文件,可以使用-c参数能解决,但是很不方便。那么gzip套件还包含了许多可以”在原地”处理压缩文件的实用程序。zcat、zgrep、zless、zdiff等作用于cat、grep、less和diff相同,但是它们的操作是压缩文件。
[root@localhost test]# zcat services.gz|head #查看压缩文件的里的内容,也可以重定向到一个新文件
# /etc/services:
# $Id: services,v 1.55 2013/04/14 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2013-04-10
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports
在使用阿里云RDS中,一般我们出于权限的考虑不会让其他用户直接进行外网访问。所以这里我们就采用Navicat加HTTP通道来访问RDS数据库。
《血色湘西》瞿先生临死前的独白,振奋人心。
Excel如何取最大值、最小值、排名第几的数据,这些都是在我们使用Excel中非常常用的功能。本文主要介绍下这几种函数的使用。
有向图根无向图的最大区别在于有向图是具有方向的,所以在实现上也会有很大的不同。
lsof命令的全称为:list open file,也就是列出系统中已经打开的文件,通过该命令就可以根据文件找到对应的进程信息,也可以根据进程信息找到进程打开的文件。 如果系统中没有lsof名,可以使用后面的命令进行安装:yum -y install lsof
快速生成表格
Electron页面跳转、浏览器打开链接和打开新窗口
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。