在Linux中解压缩tar.gz文件

We’ll look at how we can extract a tar.gz file in Linux.

我们将研究如何在Linux中提取tar.gz文件。

A tar.gz is an archive file that contains files of other types. It acts as an intermediate storage file across a network. It also compresses all these files compactly. This makes it easy to send these files.

tar.gz是包含其他类型文件的存档文件。 它充当整个网络的中间存储文件。 它还压缩所有这些文件。 这样可以轻松发送这些文件。

There are two steps involved in this process.

此过程涉及两个步骤。

  • The sender compresses all necessary files into the archive container, and sends it across a network.

    发送方将所有必需的文件压缩到存档容器中,然后通过网络发送。
  • The receiver, after getting the file, can now unpack the contents from the tar.gz archive.

    接收者在获取文件后,现在可以从tar.gz存档中解压缩内容。

We look at how we can extract this archive file format in Linux.

我们看一下如何在Linux中提取这种存档文件格式。



提取tar.gz文件 (Extract the tar.gz file)

We can use the tar command to unpack such a file. If this file is compressed using a gzip compressor, the following command applies:

我们可以使用tar命令来解压缩这样的文件。 如果使用gzip压缩程序压缩了此文件,则以下命令适用:


tar -xzf filename.tar.gz

Here, filename.tar.gz is the archive that you wish to unpack.

在这里, filename.tar.gz是您要解压缩的存档。

This means, that we instruct the tar command to:

这意味着,我们指示tar命令执行以下操作:

  • x -> Extract the files

    x- >提取文件
  • z -> This filters the archive using gzip

    z- >使用gzip过滤存档
  • f -> Use an archive file

    f- >使用存档文件

The archive name must come immediately after the f option.

归档名称必须紧接在f选项之后。

If we want tar to display more information about the files, we can also specify the -v verbose option.

如果我们希望tar显示有关文件的更多信息,我们还可以指定-v详细选项。


tar -xvzf filename.tar.gz
Extract Gzip File
Extract Gzip File
提取Gzip文件

不使用gzip提取 (Extract without using gzip)

For some reason, if this doesn’t work, try typing the following command, without using gzip.

由于某种原因,如果这不起作用,请尝试键入以下命令,而不使用gzip


tar -xf filename.tar.gz
Extract Without Gzip
Extract Without Gzip
没有Gzip的提取

As you can observe, since we packed our archive without the -z option (without gzip), we cannot use the -z option when we unpack it. So, we have to un-compress it normally.

如您所见,由于打包文件时没有-z选项(不带gzip ),因此在解压缩-z时,不能使用-z选项。 因此,我们必须正常解压缩它。

解压到指定目录 (Extract to a specified Directory)

We can extract the archive to any directory by specifying the -C option. This tells tar to change the directory before unpacking.

通过指定-C选项,我们可以将存档提取到任何目录。 这告诉tar在解tar之前先更改目录。


tar -xvzf filename.tar.gz -C ~/path/to/extract
Extract To Directory
Extract To Directory
提取到目录

You can see that the unpacked contents are indeed stored to ~/random.

您会看到解压缩的内容确实存储到~/random



结论 (Conclusion)

Hopefully, this article clears any lingering doubts about how you could extract a tar.gz file in Linux. Otherwise, feel free to ask any questions in the comment section below!

希望本文清除了有关如何在Linux中提取tar.gz文件的所有疑虑。 否则,请随时在下面的评论部分中提出任何问题!

参考资料 (References)



翻译自: https://www.journaldev.com/35544/extract-tar-gz-file-in-linux

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值