Linux 如何提取 filename.tar.gz 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15744023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:37:33  来源:igfitidea点击:

How to extract filename.tar.gz file

linuxfilegziptar

提问by Kabir

I want to extract an archive named filename.tar.gz.

我想提取一个名为filename.tar.gz.

Using tar -xzvf filename.tar.gzdoesn't extract the file. it is gives this error:

使用tar -xzvf filename.tar.gz不会提取文件。它给出了这个错误:

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error exit delayed from previous errors

采纳答案by pce

If file filename.tar.gzgives this message: POSIX tar archive, the archive is a tar, not a GZip archive.

如果file filename.tar.gz给出此消息:POSIX tar 存档,则存档是 tar,而不是 GZip 存档。

Unpack a tar without the z, it is for gzipped (compressed), only:

解压没有 tar 的 tar z,它仅用于 gzip 压缩(压缩):

mv filename.tar.gz filename.tar # optional
tar xvf filename.tar

Or try a generic Unpacker like unp(https://packages.qa.debian.org/u/unp.html), a script for unpacking a wide variety of archive formats.

或者尝试一个通用的 Unpacker,比如unp( https://packages.qa.debian.org/u/unp.html),一个用于解压各种归档格式的脚本。

determine the file type:

确定文件类型:

$ file ~/Downloads/filename.tbz2
/User/Name/Downloads/filename.tbz2: bzip2 compressed data, block size = 400k

回答by thelr

As far as I can tell, the command is correct, ASSUMING your input file is a valid gzipped tar file. Your output says that it isn't. If you downloaded the file from the internet, you probably didn't get the entire file, try again.

据我所知,该命令是正确的,假设您的输入文件是有效的 gzipped tar 文件。你的输出说它不是。如果您从 Internet 下载文件,您可能没有获得整个文件,请重试。

Without more knowledge of the source of your file, nobody here is going to be able to give you a concrete solution, just educated guesses.

如果没有更多关于文件来源的知识,这里没有人能够给你一个具体的解决方案,只是有根据的猜测。

回答by built1n

A tar.gz is a tar file inside a gzip file, so 1st you must unzip the gzip file with gunzip -d filename.tar.gz, and then use tarto untar it. However, since gunzipsays it isn't in gzip format, you can see what format it is in with file filename.tar.gz, and use the appropriate program to open it.

tar.gz 是 gzip 文件中的 tar 文件,因此首先您必须使用 解压缩 gzip 文件gunzip -d filename.tar.gz,然后使用tar解压它。但是,既然gunzip说它不是 gzip 格式,您可以查看它是什么格式file filename.tar.gz,然后使用适当的程序打开它。

回答by mcragun

Check to make sure that the file is complete. This error message can occur if you only partially downloaded a file or if it has major issues. Check the MD5sum.

检查以确保文件完整。如果您只下载了部分文件或文件存在重大问题,则会出现此错误消息。检查 MD5sum。

回答by Volkan

It happens sometimes for the files downloaded with "wget" command. Just 10 minutes ago, I was trying to install something to server from the command screen and the same thing happened. As a solution, I just downloaded the .tar.gz file to my machine from the web then uploaded it to the server via FTP. After that, the "tar" command worked as it was expected.

对于使用“wget”命令下载的文件,有时会发生这种情况。就在 10 分钟前,我试图从命令屏幕向服务器安装一些东西,同样的事情发生了。作为解决方案,我只是将 .tar.gz 文件从网络下载到我的机器,然后通过 FTP 将其上传到服务器。之后,“tar”命令按预期工作。

回答by Anton Paule

Internally tar xcvf <filename>will call the binary gzipfrom the PATHenvironment variable to decompress the files in the tararchive. Sometimes third party tools use a custom gzipbinary which is not compatible with the tarbinary. It is a good idea to check the gzipbinary in your PATHwith which gzipand make sure that a correct gzipbinary is called.

在内部tar xcvf <filename>会调用二进制gzipPATH环境变量在文件解压缩tar档案。有时第三方工具使用gziptar二进制文件不兼容的自定义二进制文件。这是一个好主意,检查gzip二进制在你PATHwhich gzip,并确保正确的gzip二进制文件被调用。

回答by EL missaoui habib

I have the same error the result of command :

我有同样的错误命令的结果:

file hadoop-2.7.2.tar.gz

is hadoop-2.7.2.tar.gz: HTML document, ASCII text

hadoop-2.7.2.tar.gz: HTML document, ASCII text

the reason that the file is not gzip format due to problem in download or other.

由于下载或其他问题,文件不是gzip格式的原因。

回答by David Castro

The other scenario you mush verify is that the file you're trying to unpack is not empty and is valid.

您必须验证的另一种情况是您尝试解压缩的文件不是空的并且是有效的。

In my case I wasn't downloading the file correctly, after double check and I made sure I had the right file I could unpack it without any issues.

在我的情况下,我没有正确下载文件,经过仔细检查,我确保我有正确的文件,我可以毫无问题地解压它。