Curl Cheat Sheet
Table of Contents:
CURL GET/HEAD
- command: curl -I https://quickref.me
- description: curl sends a request
- command: curl -v -I https://quickref.me
- description: curl request with details
- command: curl -X GET https://quickref.me
- description: use explicit http method for curl
- command: curl –noproxy 127.0.0.1 http://www.stackoverflow.com
- description: curl without http proxy
- command: curl –connect-timeout 10 -I -k https://quickref.me
- description: curl has no timeout by default
- command: curl –verbose –header “Host: www.mytest.com:8182” quickref.me
- description: curl get extra header
- command: curl -k -v https://www.google.com
- description: curl get response with headers
Prettify json output for curl response
$ curl -XGET http://${elasticsearch_ip}:9200/_cluster/nodes | python -m json.toolCURL POST
| command | description |
|---|---|
| curl -d “name=username&password=123456” |
curl send request |
| curl |
curl sends json |
CURL script install rvm
curl -sSL https://get.rvm.io | bashCURL Advanced
- command: curl -L -s http://ipecho.net/plain, curl -L -s http://whatismijnip.nl
- description: get my public IP
- command: curl -u $username:$password http://repo.dennyzhang.com/README.txt
- description: curl with credentials
- command: curl -v -F key1=value1 -F [email protected]
- description: curl upload
- command: curl -k -v –http2 https://www.google.com/
- description: use http2 curl
- command: curl -T cryptopp552.zip -u test:test ftp://10.32.99.187/
- description: curl ftp upload
- command: curl -u test:test ftp://10.32.99.187/cryptopp552.zip -o cryptopp552.zip
- description: curl ftp download
- command: curl -v -u admin:admin123 –upload-file package1.zip http://mysever:8081/dir/package1.zip
- description: upload with credentials curl
Check website response time
curl -s -w \
'\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nAppCon time:\t%{time_appconnect}\nRedirect time:\t%{time_redirect}\nPreXfer time:\t%{time_pretransfer }\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' \
-o /dev/null https://www.google.comUse Curl to check if a remote resource is available
curl -o /dev/null --silent -Iw "%{http_code}" https://example.com/my.remote.tarball.gzDownloading file
curl https://example.com | \
grep --only-matching 'src="[^"]*.[png]"' | \
cut -d \" -f2 | \
while read i; do curl https://example.com/"${i}" \
-o "${i##*/}"; doneDownload all PNG files from the site (using GNU grep)
Download the file, save the file without changing its name
curl --remote-name "https://example.com/linux-distro.iso"rename file
curl --remote-name "http://example.com/index.html" --output foo.htmlcontinue partial download
curl --remote-name --continue-at -"https://example.com/linux-distro.iso"Download files from multiple domains
curl "https://www.{example,w3,iana}.org/index.html" --output "file_#1.html"Download a series of files
curl "https://{foo,bar}.com/file_[1-4].webp" --output "#1_#2.webp"Download a series of files (output foo_file1.webp, foo_file2.webp...bar_file1_webp, etc.)
Redirect output to file
$ curl http://url/file > fileBasic Authentication
$ curl --user username:password http://example.com/
$ curl -u username:password http://example.com/Write to file instead of stdout
$ curl -o file http://url/file
$ curl --output file http://url/fileDownload header information
$ curl -I url
# display header informationWrite output to a file named remote_file
$ curl -o file http://url/file
$ curl --output file http://url/fileExecute remote script
$ curl -s http://url/myscript.shConfiguration file
curl -K file
# read configuration from file
curl --config file
$HOME/.curlrc # default configuration file on UNIX-like systems