logo
🐧 Linux 命令

Curl

Curl Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。

📂 分类 · Linux 命令🧭 Markdown 速查🏷️ 2 个标签
#curl#http
向下滚动查看内容
返回全部 Cheat Sheets

Getting Started

Introduction

Curl is a tool for transferring data between servers, supporting protocols, including:

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

{.cols-3 .marker-none}


Options
BASH
滚动查看更多
-o <file>    # --output: write to file
-u user:pass # --user: authentication

BASH
滚动查看更多
-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

BASH
滚动查看更多
-i  # --include: include HTTP headers in the output
-I  # --head: header only
Request
BASH
滚动查看更多
-X POST # --request
-L # If the page redirects, follow the link
-F # --form: HTTP POST data for multipart/form-data
data
BASH
滚动查看更多
# --data: HTTP post data
# URL encoding (eg, status="Hello")
-d 'data'

# --data pass file
-d @file

# --get: send -d data via get
-G
Header information Headers
BASH
滚动查看更多
-A <str>      # --user-agent

-b name=val   # --cookie

-b, --cookie FILE           # Load cookies from the specified file for the URL
-c, --cookie-jar FILE       # Save cookies to the specified file from the URL

-H "X-Foo: y" # --header

--compressed  # use deflate/gzip
SSL
BASH
滚动查看更多
    --cacert <file>
    --capath <dir>
BASH
滚动查看更多
-E, --cert <cert> # --cert: client certificate file
    --cert-type # der/pem/eng
-k, --insecure # For self-signed certificates

Install

BASH
滚动查看更多
apk add --update curl # install in alpine linux

Example

CURL GET/HEAD
commanddescription
curl -I https://cheatsheets.zipcurl sends a request
curl -v -I https://cheatsheets.zipcurl request with details
curl -X GET https://cheatsheets.zipuse explicit http method for curl
curl --noproxy 127.0.0.1 http://www.stackoverflow.comcurl without http proxy
curl --connect-timeout 10 -I -k https://cheatsheets.zipcurl has no timeout by default
curl --verbose --header "Host: www.mytest.com:8182" cheatsheets.zipcurl get extra header
curl -k -v https://www.google.comcurl get response with headers
Multiple file upload
BASH
滚动查看更多
$ curl -v --include \
--form key1=value1 \
    --form upload=@localfilename URL
Prettify json output for curl response
BASH
滚动查看更多
$ curl -XGET http://${elasticsearch_ip}:9200/_cluster/nodes | python -m json.tool
CURL POST
commanddescription
curl -d "name=username&password=123456" <URL>curl send request
curl <URL> -H "content-type: application/json" -d "{ \"woof\": \"bark\"}"curl sends json
CURL script install rvm
SHELL
滚动查看更多
curl -sSL https://get.rvm.io | bash
CURL Advanced
commanddescription
curl -L -s http://ipecho.net/plain, curl -L -s http://whatismijnip.nlget my public IP
curl -u $username:$password http://repo.dennyzhang.com/README.txtcurl with credentials
curl -v -F key1=value1 -F upload=@localfilename <URL>curl upload
curl -k -v --http2 https://www.google.com/use http2 curl
curl -T cryptopp552.zip -u test:test ftp://10.32.99.187/curl ftp upload
curl -u test:test ftp://10.32.99.187/cryptopp552.zip -o cryptopp552.zipcurl ftp download
curl -v -u admin:admin123 --upload-file package1.zip http://mysever:8081/dir/package1.zipupload with credentials curl
Check website response time
SHELL
滚动查看更多
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.com
Use Curl to check if a remote resource is available
BASH
滚动查看更多
curl -o /dev/null --silent -Iw "%{http_code}" https://example.com/my.remote.tarball.gz
Downloading file
BASH
滚动查看更多
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)

Download the file, save the file without changing its name
BASH
滚动查看更多
curl --remote-name "https://example.com/linux-distro.iso"

Rename file

BASH
滚动查看更多
curl --remote-name "http://example.com/index.html" --output foo.html
continue partial download
BASH
滚动查看更多
curl --remote-name --continue-at -"https://example.com/linux-distro.iso"
Download files from multiple domains
BASH
滚动查看更多
curl "https://www.{example,w3,iana}.org/index.html" --output "file_#1.html"
Download a series of files
BASH
滚动查看更多
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
BASH
滚动查看更多
$ curl http://url/file > file
Basic Authentication
BASH
滚动查看更多
$ curl --user username:password http://example.com/
$ curl -u username:password http://example.com/
Write to file instead of stdout
BASH
滚动查看更多
$ curl -o file http://url/file
$ curl --output file http://url/file
Download header information
BASH
滚动查看更多
$ curl -I url
# display header information
Write output to a file named remote_file
BASH
滚动查看更多
$ curl -o file http://url/file
$ curl --output file http://url/file
Execute remote script
BASH
滚动查看更多
$ curl -s http://url/myscript.sh
Configuration file
BASH
滚动查看更多
curl -K file
# read configuration from file
curl --config file
$HOME/.curlrc # default configuration file on UNIX-like systems

相关 Cheat Sheets

1v1免费职业咨询
logo

Follow Us

linkedinfacebooktwitterinstagramweiboyoutubebilibilitiktokxigua

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-airwallex.png/image/layout/pay-alipay.png

地址

Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)
Level 2, 171 La Trobe St, Melbourne VIC 3000
四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号
Business Hub, 155 Waymouth St, Adelaide SA 5000

Disclaimer

footer-disclaimerfooter-disclaimer

JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.

匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议

© 2017-2025 JR Academy Pty Ltd. All rights reserved.

ABN 26621887572