linux压缩命令gzip_Linux gzip命令示例

linux压缩命令gzip

Linux offers an array of tools for compressing and decompressing files. In this tutorial, we take a look at the Linux gzip command tool.

Linux提供了一系列用于压缩和解压缩文件的工具。 在本教程中,我们将研究Linux gzip命令工具。

Gzip is a file format as well as a software application which was created by Mark Adler and Jean-Loup Gailly and has been in use since the early Unix Systems.

Gzip是Mark Adler和Jean-Loup Gailly创建的一种文件格式以及一种软件应用程序,自早期Unix Systems以来就一直在使用。

Linux gzip command uses the (LZ77) Lempel-Ziv coding during its operations. Let’s dive in and see the various examples of how Gzip can be used.

Linux gzip命令在操作期间使用(LZ77)Lempel-Ziv编码。 让我们深入了解如何使用Gzip的各种示例。

使用Linux gzip命令压缩文件 (Compress a File using Linux gzip Command)

Compressing a file with gzip command is a walk in the park. Simply pass the file name as the argument as shown.

用gzip命令压缩文件是在公园散步。 只需将文件名作为参数传递即可,如图所示。

$ gzip [filename]

The final compressed file acquires a suffix .gz.

最终的压缩文件将获得后缀.gz

For example, I have 4 text files in my current working directory as shown below.

例如,我当前的工作目录中有4个文本文件,如下所示。

To compress file1.txt using gzip, the syntax will be.

要使用gzip压缩file1.txt ,语法将是。

$ gzip file1.txt

To view the compressed file, use the ls command.

要查看压缩文件,请使用ls命令。

Output

输出量

It’s worth noting that the original text file has now been compressed and bears the .gz compression suffix.

值得注意的是,原始文本文件现已压缩,并带有.gz压缩后缀。

强制gzip不替换/删除原始文件 (Force gzip not to replace/delete the original file)

As we have seen in the previous example, gzip replaces the original file and turns it into a compressed file.
However, you can opt to retain the original file using the -k option as shown.

正如我们在前面的示例中看到的那样,gzip替换了原始文件并将其转换为压缩文件。
但是,您可以选择使用-k选项保留原始文件,如图所示。

gzip -k [file-name]

For example, to compress file1.txt to a .gz file whie retaining the same file execute the command.

例如,要将file1.txt压缩为保留相同文件的.gz文件,请执行以下命令。

$ gzip -k file1.txt

Be sure to verify using the ls command and note that the original file1.txt file is still present.

确保使用ls命令进行验证,并注意原始的file1.txt文件仍然存在。

使用gzip递归压缩文件 (Recursively compress files using gzip)

To compress all files recursively inside a directory, use the -r option as shown.

要递归压缩目录中的所有文件,请使用-r选项,如图所示。

$ gzip -r *

For example, there are 4 text file inside the test folder as shown.

例如,如图所示, 测试文件夹中有4个文本文件。

To compress all the files at a go run:

要一次性压缩所有文件:

$ gzip -r *

Output

输出量

使用gzip解压缩文件 (Uncompress a file using gzip)

If you want to uncompress a file, use the -d option a shown in the syntax below.

如果要解压缩文件,请使用-d选项,语法如下所示。

$ gzip -d [compressed file-name]

For instance, to uncompress file1.txt.gz run:

例如,要解压缩file1.txt.gz,请运行:

$ gzip -d file1.txt.gz

Output

输出量

As you can see, the original compressed file disappears.

如您所见,原始压缩文件消失了。

列出使用gzip压缩文件的详细信息 (List details of a compressed file using gzip)

To list details of a compressed file make use of the -l option as shown.

要列出压缩文件的详细信息,请使用-l选项,如图所示。

$ gzip -l [compressed-file-name]

For example,

例如,

$ gzip -l file1.txt.gz

Output

输出量

如何调节gzip压缩的速度 (How to Regulate Speed of gzip Compression)

Gzip command also allows you to regulate the speed of compression. You can achieve this by specifying a hyphen (-) followed by a digit or number between 1 (Fastest) to 9 (Best). The default compression speed is 6.

Gzip命令还允许您调节压缩速度。 您可以通过指定连字符(-)后接1(最快)到9(最佳)之间的数字或数字来实现此目的。 默认压缩速度为6。

gzip -5 [file-name]

For instance:

例如:

gzip -5 file1.txt

You can use any digit/number between 1 and 9, where 1 denotes the fastest compression rate and 9 denotes the slowest compression rate but the most preferred.

您可以使用1到9之间的任何数字/数字,其中1表示最快的压缩率,而9表示最慢的压缩率,但最优选。

And that wraps up the gzip command usage. Feel free to share your thoughts on this. Your feedback is most welcome.

这样就结束了gzip命令的用法。 随时分享您的想法。 非常欢迎您提供反馈。

翻译自: https://www.journaldev.com/30260/linux-gzip-command-examples

linux压缩命令gzip

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值