首页 > 编程知识 正文

linux解压所有.tar.gz的文件,linux压缩tar.gz命令

时间:2023-05-05 11:56:43 阅读:195239 作者:1129

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 提取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 没有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 提取到目录

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) StackOverflow Question

StackOverflow问题



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

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。