【问题标题】:Curl Downloads tar.gz file as ASCIICurl 以 ASCII 格式下载 tar.gz 文件
【发布时间】:2018-12-03 05:52:47
【问题描述】:

我正在尝试使用 curl 从 github 存储库下载 tar.gz 文件,但它显然是在下载纯 ASCII 码,因此我无法解压缩或解压缩文件(如 file 命令所证明的那样 - 请参阅下面是我的堆栈跟踪的第三行)。

另一个重要细节是它在 AWS CodeBuild 实例中运行。但是,我可以在我的 mac 上使用 curl 下载它,它是一个正确的 tar.gz 文件。

这是我正在运行的命令:

curl -Lk0s https://github.com/gohugoio/hugo/releases/download/v0.49/hugo_0.49_Linux-64bit.tar.gz -o /tmp/hugo.tar.gz

完整的堆栈跟踪是:

[Container] 2018/12/03 05:39:44 Running command curl -Lk0s https://github.com/gohugoio/hugo/releases/download/v0.49/hugo_0.49_Linux-64bit.tar.gz -o /tmp/hugo.tar.gz
[Container] 2018/12/03 05:39:45 Running command file /tmp/hugo.tar.gz
/tmp/hugo.tar.gz: ASCII text, with no line terminators ***[NB. This is the output of the file command]***
[Container] 2018/12/03 05:39:45 Running command tar xvf /tmp/hugo.tar.gz -C /tmp
tar: This does not look like a tar archive
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
[Container] 2018/12/03 05:39:45 Command did not exit successfully tar xvf /tmp/hugo.tar.gz -C /tmp exit status 2
[Container] 2018/12/03 05:39:45 Phase complete: INSTALL Success: false
[Container] 2018/12/03 05:39:45 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: tar xvf /tmp/hugo.tar.gz -C /tmp. Reason: exit status 2

我在这里做错了什么?

【问题讨论】:

标签: linux unix curl github


【解决方案1】:

-L 对我有用:

curl -L https://github.com/gohugoio/hugo/releases/download/v0.49/hugo_0.49_Linux-64bit.tar.gz -o /tmp/hugo.tar.gz

我先尝试了没有任何标志,它下载了重定向页面。

添加了 -L 以跟踪重定向,结果是一个格式良好、完整的 .tar.gz 文件,可以完美解压缩。结果是一个文件夹,里面有几个文件:

$ ls -l
total 41704
-rw-r--r--  1 xxxxxxxxxxx  staff     11357 Sep 24 05:54 LICENSE
-rw-r--r--  1 xxxxxxxxxxx  staff      6414 Sep 24 05:54 README.md
-rwxr-xr-x  1 xxxxxxxxxxx  staff  21328256 Sep 24 06:03 hugo

更新:起初我没有尝试您的参数集 (-Lk0s),假设它对我也不起作用。但我刚刚尝试过,它对我有用。我得到与使用 -L 相同的 .tar.gz 并且它可以准确解压缩。请对下载的文本文件的内容进行分类,并在此处至少显示其中的一些内容。这可能是某种错误以纯文本或 html 形式发回。

【讨论】:

    猜你喜欢
    • 2021-10-18
    • 1970-01-01
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 2014-04-05
    • 1970-01-01
    相关资源
    最近更新 更多