Linux 如何使用 cURL 从 GitHub 下载 tarball?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5746325/
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
How do I download a tarball from GitHub using cURL?
提问by saltycrane
I am trying to download a tarball from GitHub using cURL, but it does not seem to be redirecting:
我正在尝试使用cURL从 GitHub 下载 tarball ,但它似乎没有重定向:
$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2
<html><body>You are being <a href="https://nodeload.github.com/pinard/Pymacs/tarball/v0.24-beta2">redirected</a>.</body></html>
Note: wget works for me:
注意:wget 对我有用:
$ wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2
However I want to use cURL because ultimately I want to untar it inline with something like:
但是我想使用 cURL 因为最终我想用以下内容内联解压它:
$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx
I found that the URL after redirecting turned out to be https://download.github.com/pinard-Pymacs-v0.24-beta1-0-gcebc80b.tar.gz, but I would like cURL to be smart enough to figure this out.
我发现重定向后的 URL 原来是https://download.github.com/pinard-Pymacs-v0.24-beta1-0-gcebc80b.tar.gz,但我希望 cURL 足够聪明来计算这个出来。
采纳答案by saltycrane
Use the -L
option to follow redirects:
使用-L
选项跟随重定向:
curl -L https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx
回答by knittl
You can also use wget to ?untar it inline?. Simply specify stdout as the output file (-O -
):
您还可以使用 wget 来“内联解压”。只需将 stdout 指定为输出文件 ( -O -
):
wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2 -O - | tar xz
回答by Pavel Repin
The modernized way of doing this is:
这样做的现代化方法是:
curl -sL https://github.com/user-or-org/repo/archive/sha1-or-ref.tar.gz | tar xz
Replace user-or-org
, repo
, and sha1-or-ref
accordingly.
相应地替换user-or-org
、repo
、 和sha1-or-ref
。
If you want a zip file instead of a tarball, specify .zip
instead of .tar.gz
suffix.
如果您想要 zip 文件而不是 tarball,请指定.zip
而不是.tar.gz
后缀。
You can also retrieve the archive of a private repo, by specifying -u token:x-oauth-basic
option to curl. Replace token
with a personal access token.
您还可以通过指定-u token:x-oauth-basic
curl 选项来检索私有存储库的存档。替换token
为个人访问令牌。
回答by zhengquan
with a specific dir
具有特定目录
cd your_dir && curl -L https://download.calibre-ebook.com/3.19.0/calibre-3.19.0-x86_64.txz | tar zx
cd your_dir && curl -L https://download.calibre-ebook.com/3.19.0/calibre-3.19.0-x86_64.txz | tar zx
回答by F1Linux
All the other solutions require specifying a release/version number which obviously breaks automation.
所有其他解决方案都需要指定一个发布/版本号,这显然会破坏自动化。
This solution however can be used programmatically to grab the LATESTrelease without specifying any tag or release number and un-TARs the binary to an arbitrary name you specify in switch --one-top-level="pi-ap"
. Just swap-out user f1linuxand repo pi-apin below example with your own details and Bob's your uncle:
但是,此解决方案可以以编程方式用于获取最新版本,而无需指定任何标签或版本号,并将二进制文件解压缩为您在 switch 中指定的任意名称--one-top-level="pi-ap"
。只需在下面的示例中替换用户f1linux和 repo pi-ap并使用您自己的详细信息,而 Bob 是您的叔叔:
curl -L https://api.github.com/repos/f1linux/pi-ap/tarball | tar xzvf - --one-top-level="pi-ap" --strip-components 1