linux - Curl 以 ASCII 格式下载 tar.gz 文件
问题描述
我正在尝试使用 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
我在这里做错了什么?
解决方案
-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 形式发回。
推荐阅读
- c++ - 谷歌测试中的 EXPECT_NO_DEATH()
- php - ajax 文件名作为二进制发送
- webassembly - Wasmer 中的“将其嵌入其他语言”是什么意思?
- java - 为什么我在使用 Retrofit 和 GSON 转换器映射的对象属性上得到空值?
- c# - 提交时的 ASP.NET MVC C# 电子邮件通知
- windows - NTUSER reg 条目不会反映在当前用户中
- android - 在android中使用依赖微调器(多个微调器)的问题
- .net - 动态 TableLayoutPanel 控件保持边框宽度
- delphi - 检查 Delphi OLE 连接是否仍然存在
- python - 导入自定义模块python时省略子目录