【运维备忘录】之 Curl 命令

运维人员不仅要熟悉操作系统、服务器、网络等只是,甚至对于开发相关的也要有所了解。很多运维工作者可能一时半会记不住那么多命令、代码、方法、原理或者用法等等。这里我将结合自身工作,持续给大家更新运维工作所需要接触到的知识点,希望大家喜欢。

今天我们要讲的是 Curl 命令


 一、简介

Curl 是一个免费和开源的软件,是一个在服务器之间传输数据的工具,支持协议包括:

HTTP、HTTPS、FTP、IMAP、LDAP、POP3、SCP、SFTP、SMB、SMTP、etc...

官方下载地址:Curl Releases and Downloads 

 二、命令参数

参数备注
-o <file># --output: write to file
-u user:pass# --user: authentication
-v # --verbose: Make curl verbose during operation
-vv# more verbose
-s # --silent: don't show progress meter or errors
-S # --show-error: When used with --silent (-sS), show errors but no progress meter
-i# --include: include HTTP headers in the output
-I# --head: header only
-X POST# --request
-L# If the page redirects, follow the link
-F# --form: HTTP POST data for multipart/form-data
-d 'data'# --data: HTTP post data
-d @file# --data pass file
-G# --get: send -d data via get

三、示例

命令示例说明
curl -I https://quickref.mecurl sends a request
curl -v -I https://quickref.mecurl request with details
curl -X GET https://quickref.meuse explicit http method for curl
curl --noproxy 127.0.0.1 http://www.baidu.com/curl without http proxy
curl --connect-timeout 10 -I -k https://www.baidu.comcurl has no timeout by default
curl --verbose --header "Host: www.test.com:8182" www.baidu.comcurl get extra header
curl -k -v https://www.baidu.com/curl get response with headers
curl -d "name=username&password=123456" <URL>curl send request
curl <URL> -H "content-type: application/json" -d "{ \"woof\": \"bark\"}"curl sends json
curl -L -s http://ipecho.net/plain, curl -L -s http://www.baidu.comget my public IP
curl -u $username:$password http://www.baidu.com/README.txtcurl with credentials
curl -v -F key1=value1 -F upload=@localfilename <URL>curl upload
curl -k -v --http2 https://www.baidu.com/use http2 curl
curl -T test2024.zip -u test:test ftp://192.168.10.10/curl ftp upload
curl -u test:test ftp://192.168.10.10/test2024.zip -o test2024.zipcurl ftp download
curl -v -u admin:admin123 --upload-file package1.zip http://mysever:8081/dir/package1.zipupload with credentials curl
curl -o /dev/null --silent -Iw "%{http_code}" https://example.com/my.remote.tarball.gzUse Curl to check if a remote resource is available
curl https://example.com | \
grep --only-matching 'src="[^"]*.[png]"' | \
cut -d \" -f2 | \
while read i; do curl https://example.com/"${i}" \
-o "${i##*/}"; done
Download all PNG files from the site (using GNU grep)
curl "https://www.{example,w3,iana}.org/index.html" --output "file_#1.html"Download files from multiple domains
curl "https://{foo,bar}.com/file_[1-4].webp" --output "#1_#2.webp"Download a series of files
$ curl http://url/file > fileRedirect output to file
$ curl -s http://url/myscript.shExecute remote script
$ curl -I urldisplay header information
  • 50
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

流浪字节π

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值