目录
一. 问题说明
当执行
tar -xzf /tmp/hadoop-3.3.5.tar.gz -C /home/taiyi/yarn
命令时出现:
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
二. 问题解决
为了知道文件的格式,我们可以执行如下命令:
[root@bi8v ~]# file /tmp/hadoop-3.3.5.tar.gz
/tmp/hadoop-3.3.5.tar.gz: POSIX tar archive
The file, yarn-3.3.5.tar.gz is in the POSIX tar archive (GNU) format instead of the gzip format. It means that the file has only been archived and not compressed using gzip. The name of a file has been changed by adding the “.gz” extension. Now as we know this file is only archived and not compressed, we can extract the file removing the “z” flag as this flag is used for gzipped files only.
yarn-3.3.5.tar.gz是POSIX tar归档文件(GNU)格式,而不是gzip格式。说明文件只是没归档而没有被压缩,只是修改了文件的拓展名.gz.
现在我们可以去掉"z"去解压这个只被归档的文件因为,这个标识只用于gzip文件。
tar -xvf /tmp/hadoop-3.3.5.tar.gz -C /home/taiyi/yarn
问题解决!
三. 命令复习
压缩
tar czvf 压缩文件名.tar.gz 被压缩文件夹
解压
tar zvxf 压缩文件名.tar.gz -C 目标文件夹
-c 压缩
-x 解压
-z 支持gzip解压文件
-v 显示操作过程
-f 使用档名,请留意,在f之后要立即接档名!不要再加参数!
去除解压目录结构使用 --strip-components N
如: 压缩文件text.tar 中文件信息为 src/src1/src2/text.txt
运行 tar -zxvf text.tar --strip-components 1
结果:src1/src2/text.txt
如果运行 tar -zxvf text.tar --strip-components 3
解压结果为: text.txt
参考:
文章讲述了在尝试用tar命令解压文件时遇到gzip格式错误的问题。通过检查文件格式,发现文件实际上是POSIXtar档案而非gzip压缩文件。因此,调整tar命令,移除z标志来正确解压文件。同时,回顾了tar命令的压缩和解压语法,以及如何使用--strip-components选项去除解压目录结构。
4194

被折叠的 条评论
为什么被折叠?



