首页 > 编程知识 正文

linuxzip压缩文件命令,linux的gzip命令

时间:2023-05-04 02:57:39 阅读:212371 作者:3696

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]

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]

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]

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 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]

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]

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] 结论 (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五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。