linux运维常用命令-curl和wget

curl

curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.curl offers a busload of useful tricks like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer resume, Metalink, and more. As you will see below, the number of features will make your head spin!curl is powered by libcurl for all transfer-related features. See libcurl(3) for details.

curl是常用的一个利用URL规则在命令行下工作的文件传输工具,功能强大,作为后端开发,一般作为一个灵活的http诊断测试工具。

  • GET

保存网页文件

curl -o baidu.html http://www.baidu.com

测试状态码

curl -o /dev/null -s -w %{http_code} www.baidu.com

请求时间等

curl -o /dev/null -s -w http_code:%{http_code}\\nhttp_connect:%{http_connect}\\ncontent_type:%{content_type}\\ntime_namelookup:%{time_namelookup}\\ntime_pretransfer:%{time_pretransfer}\\ntime_connect:%{time_connect}\\ntime_starttransfer:%{time_starttransfer}\\ntime_total:%{time_total}\\nspeed_download:%{speed_download} www.baidu.com

模拟浏览器

curl -A "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.0)" http://www.baidu.com

  • POST

curl --data "param1=value1&param2=value" www.baidu.com

post json

curl -H "Content-Type: application/json" -X POST --data '{"data":"1"}' http://127.0.0.1

中文或特殊字符转码

curl --data-urlencode "param=上海" http://www.test.com

curl的功能还有很多,如上传下载等功能,但对于更多的需求,一般会使用postman等工具,操作更容易,界面也更友好,对于一些常用的接口,我一直保存在postman,当然对于postman这样强大的工具,需要另开章节。 更多curl选项,可以man一下,或者查看这里

wget

wget 是一个从网络上自动下载文件的自由工具,支持通过 HTTP、HTTPS、FTP 三个最常见的 TCP/IP协议 下载,并可以使用 HTTP 代理。”wget” 这个名称来源于 “World Wide Web” 与 “get” 的结合。

下载到指定文件

wget -O wordpress.zip http://www.test.com

限制下载速度

wget --limit-rate=300k http://www.test.com/file

断点续传

wget -c http://www.test.com/file

后台下载

wget -b http://www.linuxde.net/testfile.zip

tail -f wget-log

更多使用说明可以查看GNU官方文档

如果觉得我的文章对您有用,请在支付宝公益平台找个项目捐点钱。 @sxzhou Oct 10, 2017

奉献爱心