【运维备忘录】之 Curl 命令

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

今天我们要讲的是 Curl 命令


 一、简介

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

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

官方下载地址:Curl Releases and Downloads 

【运维备忘录】之 Curl 命令_第1张图片

 二、命令参数

参数 备注
-o # --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.me curl sends a request
curl -v -I https://quickref.me curl request with details
curl -X GET https://quickref.me use 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.com curl has no timeout by default
curl --verbose --header "Host: www.test.com:8182" www.baidu.com curl get extra header
curl -k -v https://www.baidu.com/ curl get response with headers
curl -d "name=username&password=123456" curl send request
curl -H "content-type: application/json" -d "{ \"woof\": \"bark\"}" curl sends json
curl -L -s http://ipecho.net/plain, curl -L -s http://www.baidu.com get my public IP
curl -u $username:$password http://www.baidu.com/README.txt curl with credentials
curl -v -F key1=value1 -F upload=@localfilename 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.zip curl ftp download
curl -v -u admin:admin123 --upload-file package1.zip http://mysever:8081/dir/package1.zip upload with credentials curl
curl -o /dev/null --silent -Iw "%{http_code}" https://example.com/my.remote.tarball.gz Use 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 > file Redirect output to file
$ curl -s http://url/myscript.sh Execute remote script
$ curl -I url display header information

你可能感兴趣的:(运维备忘录,运维)