linux命令gunzip
.gz
of gzip
is very popular compression format used in Linux echo system. It is old compression algorithm but provides efficiency and speed during compression and decompression operations. Compression is very efficient file types like documents, text, some images etc. gzip
compression algorithm also used in HTTP protocol to reduce traffic bandwidth.
gzip
.gz
是Linux回声系统中非常流行的压缩格式。 它是旧的压缩算法,但是在压缩和解压缩操作期间提供了效率和速度。 压缩是非常有效的文件类型,例如文档,文本,某些图像等gzip
压缩算法也用于HTTP协议中以减少流量带宽。
用gzip命令解压缩文件 (Decompress Files with gzip Command)
We can use gzip
tool in order to decompress a .gz
file. As we know there is single gzip
library which is used by different commands and scripts. In the following examples we will completely use gunzip
command. In this example we will decompress file named myinput.py.gz
我们可以使用gzip
工具来解压缩.gz
文件。 众所周知,只有一个gzip
库可供不同的命令和脚本使用。 在以下示例中,我们将完全使用gunzip
命令。 在此示例中,我们将解压缩名为myinput.py.gz
文件。
$ gzip -d myinput.py.gz
用gunzip命令解压缩 (Decompress with gunzip Command)
gunzip
command provides more simpler usage than gzip
command. Because it is designed to decompress we do not need to provide any option. We will just issue the gunzip
command and the file name like below.
gunzip
命令比gzip
命令提供更简单的用法。 因为它旨在解压缩,所以我们不需要提供任何选项。 我们将只发出gunzip
命令和如下文件名。
$ gunzip myinput.py.gz
解压缩后保留压缩和解压缩的文件 (Keep Compressed and Decompressed File After Decompress)
gunzip
will remote compressed files after successfully decompress operation by default. If we need compressed file in the future we can avoid this behavior with -k
option which means “keep this file after decompression”.
默认情况下, gunzip
将在成功解压缩操作后远程压缩文件。 如果将来需要压缩文件,可以使用-k
选项避免这种情况,这意味着“解压缩后保留此文件”。
$ gunzip -k myinput.py.gz
强制解压缩 (Decompress Forcibly)
Some times we can decompression with gunzip
can create issues. This can prevent the compression because of created errors or warning. This errors and warning will prevent to complete decompression. We can provide -f
force option which will complete decompression event some errors or warnings occurs.
有时我们可以用gunzip
进行减压可能会造成问题。 这样可以避免由于创建的错误或警告而导致的压缩。 此错误和警告将阻止完成减压。 我们可以提供-f
force选项,该选项将完成减压事件,并发生一些错误或警告。
$ gunzip -f myinput.py.gz
显示有关压缩文件的信息 (Display Information About Compressed File)
Compressed files will have some attributes related with compression. We may need to list these attributes in order to get more information about the compression. We can list these attributed with -l
option.
压缩文件将具有一些与压缩有关的属性。 为了获得有关压缩的更多信息,我们可能需要列出这些属性。 我们可以使用-l
选项列出这些属性。
$ gunzip -l myinput.py.gz
The following compression related attributes will be listed.
将列出以下与压缩有关的属性。
- `Compressed Size` will show compressed file size “压缩大小”将显示压缩文件的大小
- `Uncompressed Size` will show uncompressed file size`Uncompressed Size`将显示未压缩的文件大小
- `Ratio` will show the compression ratio by dividing compressed size to uncompressed size“比率”将通过将压缩大小除以未压缩大小来显示压缩率
- `Uncompressed Filename` will show filename in the archive.“未压缩的文件名”将在档案中显示文件名。
递归解压缩 (Decompress Recursively)
As we can compress recursively files in directories we may need to decompress them. Decompressing one by one entering to the directory is not feasibly. So we can decompress them recursively by using -r
option. We will decompress all gz
file in the directory named oldbackup
.
由于我们可以递归压缩目录中的文件,因此可能需要解压缩它们。 不能一一解压进入目录。 因此,我们可以使用-r
选项来递归地解压缩它们。 我们将解压缩名为oldbackup
的目录中的所有gz
文件。
$ gzip -r oldbackup/
检查压缩文件的完整性和有效性 (Check Compressed File Integrity and Validity)
Some file get corrupted during compression or after compression. If we try to decompress them we will get some warnings or errors. We can check their integrity and validity with -t
option which means “test the .gz file”.
某些文件在压缩过程中或压缩后会损坏。 如果我们尝试解压缩它们,我们将收到一些警告或错误。 我们可以使用-t
选项检查它们的完整性和有效性,这意味着“测试.gz文件”。
$ gzip -t oldbackup/
$ gzip -t oldbackup /
关于解压缩操作的详细输出 (Verbose Output About Decompress Operation)
Up to know we have not put a lot of screenshots because gzip
command rarely output to the console. But if we need more information about the current operation we can use -v
option to print a lot of information.
众所周知,由于gzip
命令很少输出到控制台,因此我们并没有放置很多屏幕截图。 但是,如果我们需要有关当前操作的更多信息,则可以使用-v
选项来打印很多信息。
$ gunzip -v -r oldbackup/
翻译自: https://www.poftut.com/linux-gunzip-command-tutorial-examples/
linux命令gunzip