linux压缩命令gzip_如何在Linux中使用Gzip命令?

linux压缩命令gzip

The Gzip command in Linux is used for compressing and decompressing files. This command is also used as gunzip for g-un-zip i.e. to unzip a gzip archive.

Linux中的Gzip命令用于压缩和解压缩文件。 此命令还可用作g-un-zip的gunzip,即解压缩gzip存档。

It’s necessary that we compress files Expanding files is useful to open compressed files downloaded from the internet.

我们必须压缩文件扩展文件对于打开从Internet下载的压缩文件很有用。

在Linux中使用gzip命令 (Using the gzip Command in Linux)

Let’s understand how we can compress and decompress files using the gzip command in Linux.

让我们了解如何在Linux中使用gzip命令压缩和解压缩文件。

1.压缩文件 (1. Compress a file )

Compressing a file is straightforward with gzip command. You just have to mention the name of the file along with the command.

使用gzip命令可以直接压缩文件。 您只需要在命令中提及文件名即可。


$ gzip [filename]
Compress

You can see that the compressed file appears in the list with a .gz extension.

您会看到压缩文件以.gz扩展名出现在列表中。

2.压缩多个文件 (2. Compress multiple files)

To compress multiple files, specify the name of the files with spaces in between as shown below.

要压缩多个文件,请指定文件名,并在文件名之间插入空格,如下所示。


$ gzip [filename1] [filename2]
Multiple file compression with the gzip command in Linux

We can see that both the files appear with a .gz extension. If a compressed version of a file already exists then it will ask you to overwrite.

我们可以看到两个文件都以.gz扩展名出现。 如果文件的压缩版本已存在,它将要求您覆盖。

3.解压缩文件 (3. Decompress a file)

There are two ways to decompress a file. The first one is using a ‘d’ flag with gzip command.

有两种解压缩文件的方法。 第一个是在gzip命令中使用'd'标志。


$ gzip -d [filename]
Gzip command in Linux decompress

We can see that the file appears in the list as without a .gz extension.

我们可以看到该文件以.gz扩展名的形式出现在列表中。

The second way is by using gunzip command.

第二种方法是使用gunzip命令。


$ gunzip [filename]
Gunzip
Gunzip
Gunzip

4.压缩后保留原始文件 (4. Keep the original file after compression )

The gzip command removes the original file and only keeps the compressed file once the operations are completed. If you want to keep the original file as well use -k flag.

gzip命令删除原始文件,仅在操作完成后保留压缩文件。 如果还要保留原始文件,请使用-k标志。


$ gzip -k [filename]
keep the original file
with gzip command in Linux

We can see that both the original and compressed file are present in the list.

我们可以看到列表中同时存在原始文件和压缩文件。

使用Gzip命令从压缩文件中检索信息 (Using the Gzip Command to Retrieve Information from Compressed Files )

You may also need to retrieve compression and compressed file-related information from the gzip archive. You can obviously make use of the ls command to get the file size but that won’t tell you the compression ratio, and the size before and after compression.

您可能还需要从gzip存档中检索与压缩和压缩文件有关的信息。 您显然可以使用ls命令来获取文件大小,但这不会告诉您压缩率以及压缩前后的大小。

That’s where gzip’s built in functionality comes into place!

这就是gzip内置功能的地方!

1.获取有关压缩的信息 (1. Get information about the compression )

To gain information about the compression like the compression ratio usel flag.

获得关于像压缩比使用压缩信息-升标志。


$ gzip -l [filename]
Compression Info

Note that the filename is that of an already compressed file. It provides four fields of information about the compression performed.

请注意,文件名是已经压缩的文件的文件名。 它提供了有关执行的压缩的四个信息字段。

  • Compressed size

    压缩尺寸
  • Uncompressed size

    未压缩尺寸
  • Ratio

  • Uncompressed filename

    未压缩的文件名

2.显示文件内容 (2. Display contents of the file)

To display the contents of the file without decompressing, use the -c flag along with gunzip command.

要显示文件内容而不进行解压缩,请使用-c标志以及gunzip命令。


gunzip -c [filename]
gzip command in Linux - gunzip -c

结论 (Conclusion )

In this tutorial we saw how gzip and gunzip commends are useful in linux for compression and expanding of files. Compressing of files is common before attaching them in mails.

在本教程中,我们看到了gzip和gunzip推荐在Linux中如何用于压缩和扩展文件。 在将文件附加到邮件中之前,通常会压缩文件。

翻译自: https://www.journaldev.com/42345/gzip-command-in-linux

linux压缩命令gzip

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值