我有一个文本文档,其中包含一堆格式类似于以下的URL:
URL = "sitehere.com"
我想要做的是运行curl -K myfile.txt
命令,并将cURL返回的响应输出到文件中。
我该如何实现这个目标?
我有一个文本文档,其中包含一堆格式类似于以下的URL:
URL = "sitehere.com"
我想要做的是运行curl -K myfile.txt
命令,并将cURL返回的响应输出到文件中。
我该如何实现这个目标?
curl -K myconfig.txt -o output.txt
curl -K myconfig.txt >> output.txt
curl -X POST -H "Content-Type: application/octet-stream" --data-binary "@/home/path/file.xyz" "https://xample.org:8080/v1/?filename=file.xyz&food=1&z=bee" >out.txt 2>err.txt
curl url > destfile.x
。 - kodybrown--remote-name-all
选项。参考链接:https://unix.stackexchange.com/a/265819/171025 - qwrcurl --remote-name-all https://example.tld/resource{1,2,3}
。详情请参见:https://curl.se/docs/manpage.html#--remote-name-all - Little_Ye233-O
选项。谢谢! - BiBi# saves it to myfile.txt
curl http://www.example.com/data.txt -o myfile.txt
# The #1 will get substituted with the url, so the filename contains the url
curl http://www.example.com/data.txt -o "file_#1.txt"
# saves to data.txt, the filename extracted from the URL
curl http://www.example.com/data.txt -O
# saves to filename determined by the Content-Disposition header sent by the server.
curl http://www.example.com/data.txt -O -J
在这种情况下,可以使用curl
或wget
。这三个命令都能够完成相同的任务,即下载位于 http://path/to/file.txt 的文件并将其保存到本地的 "my_file.txt"。
请注意,在以下所有命令中,我也建议使用curl
的-L
或--location
选项,以便跟随HTML 302重定向到文件的新位置(如果已移动)。wget
无需额外的选项即可自动执行此操作。
# save the file locally as my_file.txt
wget http://path/to/file.txt -O my_file.txt # my favorite--it has a progress bar
curl -L http://path/to/file.txt -o my_file.txt
curl -L http://path/to/file.txt > my_file.txt
wget
或curl
配合-O
或--remote-name
选项。# save the file locally as file.txt
wget http://path/to/file.txt
curl -LO http://path/to/file.txt
curl -L --remote-name http://path/to/file.txt
-O
都是大写字母"O"。
wget
命令的好处是它会显示一个漂亮的进度条。sha512sum my_file.txt
并比较结果,可以发现这3个文件具有完全相同的sha哈希值(sha校验和),这意味着这些文件是完全相同的,逐字节比对。curl
的-L
选项:有没有办法用命令行cURL跟随重定向?wget
命令下载文件并保存为不同的文件名。pbcopy
命令。curl https://www.google.com/robots.txt | pbcopy
。这将把给定URL的所有内容复制到您的剪贴板中。curl https://www.google.com/robots.txt | xclip
Windows版本:curl https://www.google.com/robots.txt | clip
。xclip
替代请参见此问题。但在大多数情况下,我更喜欢curl http://example.com -o example_com.html&cat example_com.html | pbcopy
。这样,如果您无意中清除了剪贴板,您就不需要再次curl。 - lacostenycodercurl http://www.textfiles.com/etext/FICTION/fielding-history-243.txt | pbcopy
也许不要尝试这个! - lacostenycoder如果没有在 "URL" -o "file_output" 之间添加引号,curl 将无法识别 URL 或文本文件名。
格式
curl "url" -o filename
示例
curl "https://en.wikipedia.org/wiki/Quotation_mark" -o output_file.txt
示例_2
curl "https://en.wikipedia.org/wiki/Quotation_mark" > output_file.txt
一定要记得加上引号。
--trace-ascii output.txt
命令将curl的详细信息输出到文件output.txt
中。-vv
显示的一样(SSL信息,HTTP动词,头文件等),我想要存储它。其他答案都没有将其写入文件。 - Thor Gallecurl https://localhost:8080
--request POST
--header "Content-Type: application/json"
-o "C:\Desktop\test.json"
可能有点晚了,但我认为OP在寻找类似以下内容的东西:
curl -K myfile.txt --trace-ascii output.txt
lwp-download http://www.perl.com/CPAN/src/latest.tar.gz
http://one.example.com
和http://two.example.com
的内容,并将它们分别保存为文件名为file_one.txt
和file_two.txt
的本地文件。具体使用方法如下:curl http://{one,two}.example.com -o "file_#1.txt"
- onmyway133