每天一命令之curl

来自linux中国网wiki
Evan讨论 | 贡献2019年10月14日 (一) 13:55的版本 (导入1个版本)
跳到导航 跳到搜索

常用参数

 -L, --location      Follow redirects 进行强制重定向
     --location-trusted Like --location, and send auth to other hosts
     --login-options <options> Server login options
     --mail-auth <address> Originator address of the original email
     --mail-from <address> Mail from this address
     --mail-rcpt <address> Mail to this address


-o, --output <file> Write to file instead of stdout
-o:将文件保存为命令行中指定的文件名的文件中

-O:使用URL中默认的文件名保存文件到本地

举个栗子
curl -L linux.net/lnmp.sh -o 1.sh
把lnmp.sh 下载回来 并重命令为1.sh 



指令:curl
在linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具。它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具。


语法:# curl [option] [url]


常见参数:
-A/--user-agent <string>        设置用户代理发送给服务器
-b/--cookie <name=string/file>  cookie字符串或文件读取位置
-c/--cookie-jar <file>          操作结束后把cookie写入到这个文件中
-C/--continue-at <offset>       断点续转
-D/--dump-header <file>         把header信息写入到该文件中
-e/--referer                    来源网址
-f/--fail                       连接失败时不显示http错误
-o/--output                     把输出写到该文件中
-O/--remote-name                把输出写到该文件中,保留远程文件的文件名
-r/--range <range>              检索来自HTTP/1.1或FTP服务器字节范围
-s/--silent                     静音模式。不输出任何东西
-T/--upload-file <file>         上传文件
-u/--user <user[:password]>     设置服务器的用户和密码
-w/--write-out [format]         什么输出完成后
-x/--proxy <host[:port]>        在给定的端口上使用HTTP代理
-#/--progress-bar               用进度条显示当前的传送状态








用curl的内置option就好,存下http的结果,用这个option: -o

 curl -o page.html http://www.yahoo.com

大写的O,这么用:这样,就可以按照服务器上的文件名,自动存在本地了
 curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG


访问不到?肯定是你的proxy没有设定了。
使用curl的时候,用这个option可以指定http访问所使用的proxy服务器及其端口: -x
 curl -x 123.45.67.89:1080 -o page.html http://www.yahoo.com


下载 
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py


其它例子本身就是一个sh脚本 哈哈 写得不错 
https://test.docker.com/ 
 curl -fsSL https://test.docker.com/ | bash

curl -fsSL https://test.com/lnmp.sh | bash

-f/--fail                       连接失败时不显示http错误

-s/--silent                     静音模式。不输出任何东西

-S, --show-error    Show error. With -s, make curl show errors when they occur

-L, --location      Follow redirects (H)

or 
wget http://xxx/xxx.sh -O- | bash

指定ip访问url

指定ip访问url
curl -H 'Host:a.com' http://10.12.20.21

see also

https://www.cnblogs.com/gbyukg/p/3326825.html

http://www.21andy.com/new/20080602/1154.html http://doiido.blog.51cto.com/5503054/1564631 https://www-31.ibm.com/support/techdocs/cn/faqhtmlfaq/2311073I23001.htm