-o, –output <file>
惯例操作一:把一个申请的响应写入单个文件中
curl www.baidu.com –output “baidu.txt”
将会把百度首页的内容放入文件 baidu.txt,baidu.txt 在执行命令的当前目录生成。
惯例操作二:把多个申请的响应写入多个文件中(单个汇合变量)
curl -v https://ai.baidu.com/ai-doc/FACE/{6k37c1nva,Yk37c1o30} –output “file_#1abc.txt”
将会把两个接口 https://ai.baidu.com/ai-doc/FACE/Okg7edktq,https://ai.baidu.com/ai-doc/FACE/6k37c1nva 的内容别离存入 file_Okg7edktqabc.txt,file_Yk37c1o30abc.txt 文件中,大括号相当于汇合,外面的元素会替换掉指定的文件名中的 #1 字符。
留神:此命令在 linux 下执行 {} 须要本义,即 \{…..\}
惯例操作三:把多个申请的响应写入多个文件中(单个数组变量)
curl https://ai.baidu.com/ai-doc/FACE/Yk37c1o3[0-5] –output “b_#1.txt”
将会把六个接口:
- https://ai.baidu.com/ai-doc/FACE/Yk37c1o30
- https://ai.baidu.com/ai-doc/FACE/Yk37c1o32
- https://ai.baidu.com/ai-doc/FACE/Yk37c1o33
- https://ai.baidu.com/ai-doc/FACE/Yk37c1o34
- https://ai.baidu.com/ai-doc/FACE/Yk37c1o35
- https://ai.baidu.com/ai-doc/FACE/Yk37c1o36
的响应别离存入以下文件
- b_0.txt
- b_1.txt
- b_2.txt
- b_3.txt
- b_4.txt
- b_5.txt
惯例操作三:把多个申请的响应写入多个文件(多个汇合、多个数组变量)
curl http://{site,host}.baidu.{one,two}.host[1-5].sina[0-5].com -o “#1_#2_#3_#4”
请自行演示。
- Write output to <file> instead of stdout.
- If you are using {} or [] to fetch multiple documents, you can use ‘#’ followed by a number in the <file> specifier. That
variable will be replaced with the current string for the URL being fetched. Like in:
curl http://{one,two}.site.com -o “file_#1.txt”
or use several variables like:
curl http://{site,host}.host[1-5].com -o “#1_#2” - You may use this option as many times as the number of URLs you have.