linux - curl 命令不下载文件 (linux mint)

标签 linux curl download wget

我想用 curl 下载一个文件,但它不起作用!

 curl -O https://github.com/systems-cs-pub-ro/uso/raw/master/tema1/help/hello.o

这是我在很多官方网站上看到的例子。他们说上面的命令下载了文件 hello.o。它没有!它只是下载某种输出并将其存储在同名文件中。

如果我运行上面的命令,并打印 hello.o 的内容,它说:

 <html><body>You are being <a href="https://raw.githubusercontent.com/systems-cs-pub-ro/uso/master/tema1/help/hello.o">redirected</a>.</body></html>

hello.o 的维度是 147 字节。

另外,如果我输入

  wget https://github.com/systems-cs-pub-ro/uso/raw/master/tema1/help/hello.o

它下载文件 hello.o 究竟是怎么回事!现在,它的尺寸是 1,2 K

有没有办法使用 curl 下载 hello.o 文件,我如何使用 wget 下载它?

恭敬地感谢您。

最佳答案

对于 Curl,您需要像这样使用 -L 标志:

curl -L https://github.com/systems-cs-pub-ro/uso/raw/master/tema1/help/hello.o > 你好.o

来自 Curl 的手册页:

-L, --location (HTTP/HTTPS) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make curl redo the request on the new place. If used together with -i, --include or -I, --head, headers from all requested pages will be shown. When authentication is used, curl only sends its credentials to the initial host. If a redirect takes curl to a different host, it won't be able to intercept the user+password. See also --location-trusted on how to change this. You can limit the amount of redirects to follow by using the --max-redirs option. When curl follows a redirect and the request is not a plain GET (for example POST or PUT), it will do the following request with a GET if the HTTP response was 301, 302, or 303. If the response code was any other 3xx code, curl will re-send the following request using the same unmodified method.

请注意,您的问题已在此处得到解答: How do I download a tarball from GitHub using cURL?

关于linux - curl 命令不下载文件 (linux mint),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27458797/

相关文章:

c# - 如何避免Webclient下载0字节文件错误

javascript - 通过javascript下载文件时设置文件名

multithreading - 使用线程下载Servlet文件

linux - 如何在 bash 中对逗号分隔值进行排序?

linux - 为什么我的 ulimit 设置在 shell 中被忽略了?

php - cURL 命令不适用于 ssl

curl - 使用 cUrl 从 ftp 中删除文件

Linux BASH,如何从另一个文件添加两行

linux - Bluemix 容器 - 如何拥有 Linux

php - 相同的 cURL 脚本可以在 dev 中运行。不明白为什么没有投入生产