linux - Ubuntu 18.04 : Cannot extract downloaded tar. xz 文件用单个命令

标签 linux curl tar ubuntu-18.04 xz

我正在尝试使用单行命令下载并提取 tar.xz 文件。但是,它并不始终适用于所有链接。我可以手动下载并解压它。

我可以毫无问题地下载 glibc 并解压。

curl https://ftp.gnu.org/gnu/glibc/glibc-2.26.tar.xz | tar -xJ -C ${PWD} --strip-components 1

当下载以下文件时,意外地失败了。我不知道是什么造成了差异。这是我迄今为止看到的失败的单个链接。

知道为什么以下命令失败吗?

curl https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/arm-linux-gnueabihf/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz | tar -xJ -C ${PWD} --strip-components 1

失败并显示以下消息。

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
xz: (stdin): File format not recognized
tar: Child returned status 1
tar: Error is not recoverable: exiting now           

如有任何帮助,我们将不胜感激。

最佳答案

使用curl -L 来跟踪重定向:

curl -L https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/arm-linux-gnueabihf/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz | tar -xJ --strip-components 1

要调试此类问题,您可以单独运行 curl 命令,并观察在这种情况下,它不会返回任何数据:

$ curl https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/arm-linux-gnueabihf/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz
$

然后您可以进一步运行 curl -v 来查看发生了什么。它显示 HTTP/1.1 302 Found ,其正文为空,并重定向到另一个文件,这就是您如何知道添加 -L 来遵循重定向。

关于linux - Ubuntu 18.04 : Cannot extract downloaded tar. xz 文件用单个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59313987/

相关文章:

git - 如何将项目的新版本导入我的 git 存储库?

c++ - POSIX 信号量在高争用/负载下不起作用

Linux 中的 Python : Put user input asynchronously into queue

python - Python如何获取大文件的实时拷贝进度?

linux - 在 Openshift 上将 nodejs gear 升级到 v0.12 后出现 bcrypt 错误

curl - 运行官方 consul docker 镜像

java - zip4j可以用来解压Tar文件吗?

python - 非交互式访问谷歌云存储

java - 使用 HttpClient 发出 httpGet 请求

linux - 如何使用 Bash 在目录中压缩文件