curl commands cheat sheet
Headers and status code
-
curl -I https://example.comSends a HEAD request and shows only the status line and the response headers, without the page content. Some servers respond to a HEAD request differently than to a regular GET request.
Example:
HTTP/2 200 -
curl -i https://example.comSends a regular GET request and shows the response headers followed by the page content. The long name is --show-headers, and in older versions it was called --include.
-
curl -s -o /dev/null -w "%{http_code}\n" https://example.comShows only the status code of a GET request, such as 200, 301, or 404. The -s option hides the progress meter, and the -o option sends the page content to /dev/null instead of the screen.
Example:
200 -
curl -v https://example.com -o /dev/nullShows every stage of the request: lines that start with > are the headers sent, lines that start with < are the headers received, and lines that start with * are curl's notes about the connection.
-
curl -sI https://example.com | grep -i '^cache-control'Shows a single header from the response, in this case the caching instructions. You can replace the header name with any other header.
-
curl -s -o /dev/null -w "%header{content-type}\n" https://example.comShows the value of a single response header directly with -w, without needing grep.
Example:
text/html; charset=UTF-8 -
curl -sI --compressed https://example.com | grep -i '^content-encoding'Checks whether the server returns the page compressed. The --compressed option asks for a compressed response in the methods curl supports, and the server may ignore the request.
Example:
content-encoding: br
Redirects
-
curl -L https://example.comFollows redirects to the final URL. The default limit is 50 redirects, and credentials you set are sent only to the first host.
-
curl -sIL http://example.comShows the headers of every response in the redirect chain, for example from HTTP to HTTPS and from there to the www address, so you see each step and its status code.
Example:
HTTP/1.1 301 Moved Permanently -
curl -s -o /dev/null -w "%{redirect_url}\n" http://example.comShows where the URL redirects to, without following the redirect. When there is no redirect, an empty line is shown.
Example:
https://example.com/ -
curl -sL -o /dev/null -w "%{num_redirects} %{url_effective}\n" http://example.comShows how many redirects there were along the way and the final URL the request reached.
Example:
2 https://www.example.com/ -
curl -L --max-redirs 5 https://example.comLimits the number of redirects. When there is a redirect loop, curl stops with an error message instead of going on for 50 redirects.
Response times and connection details
-
curl -s -o /dev/null -w "dns: %{time_namelookup}\nconnect: %{time_connect}\ntls: %{time_appconnect}\nttfb: %{time_starttransfer}\ntotal: %{time_total}\n" https://example.comBreaks the load time into stages, in seconds from the start of the request: the DNS lookup, connecting to the server, completing the TLS handshake, receiving the first byte from the server (TTFB), and the total time. Each value includes the stages before it.
Example:
ttfb: 0.182341 -
curl -s -o /dev/null -w "%{remote_ip}\n" https://example.comShows the IP address of the server curl actually connected to. Useful for checking whether a DNS change has already reached your computer.
Example:
192.0.2.10 -
curl -s -o /dev/null -w "%{ssl_verify_result}\n" https://example.comShows the result of the SSL certificate verification. The value 0 means verification succeeded.
Example:
0 -
curl -s -o /dev/null -w "%{json}\n" https://example.comShows all the -w data at once, in JSON format, for saving or processing in a script.
API requests and sending data
-
curl -d "name=test&email=user@example.com" https://example.com/formSends a POST request with form data (application/x-www-form-urlencoded). Several -d options are joined together with the & character.
-
curl --data-urlencode "message=hello world" https://example.com/formSends data in a POST request and URL-encodes it, so spaces and special characters are sent correctly.
-
curl -d @data.txt https://example.com/formSends the contents of the data.txt file. With the -d option, line breaks are stripped from the file, so to send the file as is, use --data-binary @data.txt.
-
curl --json '{"name":"test"}' https://api.example.com/itemsSends JSON in a POST request and adds the Content-Type: application/json and Accept: application/json headers. The option is available in recent versions of curl.
-
curl --json @item.json https://api.example.com/itemsSends the contents of the item.json file as JSON. Handy for a long request body, and it avoids quoting problems on the command line.
-
curl -X DELETE https://api.example.com/items/42Sends a DELETE request. Caution: on a real API, the request deletes the item. Combined with -L, curl also sends DELETE to the URL the redirect points to.
-
curl --url-query "q=hello world" https://example.com/searchAdds a parameter to the URL (query string) and encodes it, in a regular GET request. The option is available in recent versions of curl.
-
curl -F "file=@report.pdf" https://example.com/uploadUploads a file in a multipart/form-data POST request, like an upload form in a browser. The name file is the field name the server expects.
-
curl -T backup.zip https://example.com/upload/Uploads a file in a PUT request. When the URL ends with /, the file name is added to the end of the URL.
Headers, User-Agent, and authentication
-
curl -H "Accept: application/json" https://api.example.com/itemsAdds a header to the request. You can use several -H options in the same command.
-
curl -H "Authorization: Bearer TOKEN" https://api.example.com/meSends an API access token. Caution: the command, including the token, is saved in the terminal's command history.
-
curl -H "User-Agent:" https://example.comA header with no value after the colon removes a header that curl sends on its own.
-
curl -A "Mozilla/5.0" https://example.comSends a different User-Agent, for example to check whether the site responds to bots differently than to browsers.
-
curl -e https://example.com/ -I https://example.com/image.pngSends a referring URL (Referer), for example to test protection against other sites using your site's images.
-
curl -u admin https://example.com/private/Basic authentication (Basic Auth) with a username. curl prompts you for the password, and the password isn't saved in the history.
-
curl -u admin:password https://example.com/private/Authentication with a username and password on one line. Caution: the password is saved in the command history and may briefly appear in the system's process list.
Cookies
-
curl -c cookies.txt https://example.com/At the end of the request, saves all the cookies the site sent to the cookies.txt file.
-
curl -b cookies.txt https://example.com/accountSends the cookies saved in the file. When the value doesn't contain the = character, curl treats it as a file name.
-
curl -b "session=abc123" https://example.com/accountSends a cookie directly from the command, without a file.
-
curl -b cookies.txt -c cookies.txt https://example.com/accountReads the cookies from the file and also saves new cookies to it, so you can chain several requests in the same session.
Testing a site on a new server before changing DNS
-
curl -I --resolve example.com:443:192.0.2.10 https://example.com/Sends the request to an IP address you choose, without changing DNS and without editing the hosts file. The site name is sent as usual, so the SSL certificate is checked against the domain name. Ideal for testing a site on a new server before moving the DNS records.
-
curl -I --resolve example.com:80:192.0.2.10 http://example.com/The same test over HTTP. The port in the --resolve option must match the port of the URL: 80 for HTTP and 443 for HTTPS.
-
curl -sIL --resolve '*:443:192.0.2.10' https://example.com/The asterisk points every name on port 443 to the new server, so a redirect from example.com to www.example.com also stays on the new server.
-
curl -s -o /dev/null -w "%{remote_ip} %{http_code}\n" --resolve example.com:443:192.0.2.10 https://example.com/Confirms that the request reached the new server and shows the status code it returns.
Example:
192.0.2.10 200 -
curl -I --connect-to example.com:443:new.example.net:443 https://example.com/Connects to a different server by name instead of by IP address. The change applies only to the network connection, and the site name and SSL certificate stay those of the original URL.
-
curl -I -H "Host: example.com" http://192.0.2.10/Connects directly to an IP address with the site name in the Host header. Suitable for HTTP only. Over HTTPS, the server picks the certificate by the name sent at the start of the connection, so use the --resolve option instead.
SSL and TLS certificates
-
curl -vI https://example.comShows the TLS connection details: the version, the selected cipher, and the certificate details, such as the name, the issuer, and the expiry date. The details shown vary with the TLS library curl is built with.
-
curl -k https://192.0.2.10/Skips SSL certificate verification. Caution: the connection is no longer secure. Use it only to test a server that doesn't have a valid certificate yet, and never to send passwords or data.
-
curl --cacert ca.pem https://intranet.example.com/Verifies the server's certificate against a certificate authority file you choose, for example your organization's internal CA, instead of turning verification off with -k.
-
curl -I --tlsv1.2 --tls-max 1.2 https://example.comConnects with TLS 1.2 only: the --tlsv1.2 option sets the minimum version, and the --tls-max option sets the maximum version. When the connection fails, the server doesn't support this version.
-
curl -I --tlsv1.3 https://example.comRequires at least TLS 1.3, and checks that the server supports the latest version.
-
curl --ssl-no-revoke https://example.comWindows only, in a build that uses the Windows TLS library (Schannel), such as the built-in one: turns off the check for whether the certificate was revoked (revocation). For testing only.
HTTP versions, network, and timing
-
curl -I --http1.1 https://example.comForces HTTP/1.1. Over HTTPS, curl tries HTTP/2 by default, so this lets you compare the two versions.
-
curl -I --http3 https://example.comTries HTTP/3 (QUIC), and falls back to an earlier version when the connection fails or is slow. Available only when curl is built with HTTP/3 support, which you can check in the feature list of curl -V.
-
curl -I --http3-only https://example.comHTTP/3 only, with no fallback to an earlier version. When the request fails, the server isn't reachable over HTTP/3 from your computer.
-
curl -4 -I https://example.comConnects over IPv4 addresses only. The -6 option connects over IPv6 addresses only, so you can check that the site is reachable over both.
-
curl --connect-timeout 5 -m 20 https://example.comLimits the connection time to 5 seconds and the whole request to 20 seconds. Useful in scripts, so a stuck request doesn't hold up the whole process.
-
curl --retry 3 https://example.comRetries up to 3 times on a transient error: a timeout, or HTTP codes 408, 429, 500, 502, 503, 504, 522, or 524. The wait starts at one second and doubles with each attempt.
-
curl -x http://192.0.2.1:3128 https://example.comSends the request through a proxy server. When no port is given, the default is 1080.
-
curl -VShows the curl version, the TLS library it is built with, the supported protocols, and the feature list (Features), such as HTTP2 and HTTP3.
Downloading files
-
curl -o page.html https://example.comSaves the content to a file with a name you choose, instead of showing it on the screen.
-
curl -O https://example.com/file.zipSaves the file under the name at the end of the URL. Caution: an existing file with the same name is overwritten.
-
curl -L -O https://example.com/download/file.zipDownloads a file from a URL that redirects to another location. Without the -L option, curl saves the redirect response instead of the file.
-
curl -C - -O https://example.com/big.isoResumes an interrupted download from where it stopped. The dash after -C tells curl to work out where to resume on its own.
-
curl --limit-rate 1M -O https://example.com/big.isoLimits the download speed to 1 megabyte per second, so it doesn't take up all the bandwidth of the connection.
-
curl -r 0-1023 -o part.bin https://example.com/file.zipDownloads only the first 1,024 bytes of the file. The server must support partial requests (Range).
-
curl -fsSL -o install.sh https://example.com/install.shThe common combination in scripts: the -f option fails without saving the content when the server returns a code of 400 or higher, the -s option hides the progress meter, the -S option still shows error messages, and the -L option follows redirects. Caution: read a script you downloaded before you run it.
-
curl --fail-with-body https://api.example.com/itemsLike the -f option, but also shows the response body when the server returns an error, so you can see the API's error message. The option is available in recent versions of curl.
-
curl -Z -O https://example.com/a.zip -O https://example.com/b.zipDownloads several files in parallel instead of one after another.
Your public IP address
-
curl https://www.ereznet.co.il/ipReturns the public IP address of your connection as one line of text. On a server, the command shows the address the server uses to reach the internet.
Example:
198.51.100.23 -
curl -4 https://www.ereznet.co.il/ipShows the public IPv4 address of the connection.
-
curl -6 https://www.ereznet.co.il/ipShows the public IPv6 address, when your connection supports IPv6.
Example:
2001:db8::23
curl on Windows
-
curl.exe -I https://example.comcurl comes installed on every Windows 10 and Windows 11 computer. In Windows PowerShell, the word curl runs Invoke-WebRequest, so you type curl.exe with the extension.
-
curl.exe -s -o NUL -w "%{http_code}" https://example.comOn Windows, you write NUL instead of /dev/null. In a batch file, write %% instead of % inside -w.
-
curl.exe --json @item.json https://api.example.com/itemsIn CMD and PowerShell, JSON with quotes is hard to type, so it is easier to save the request body in a file.
-
curl.exe -VThe version built into Windows uses the Windows TLS library and doesn't support HTTP/2 or HTTP/3. For these tests, install a full build of curl.
Exit codes and errors
-
echo $?Shows the exit code of the last command on Linux and macOS. The code 0 means the request succeeded. In CMD, type echo %errorlevel%.
-
curl: (6)The server name can't be resolved in DNS. Check that the URL has no typo and that the domain is set up.
-
curl: (7)Connecting to the server failed: the server is unavailable, the service isn't running on the port, or a firewall is blocking the connection.
-
curl: (22)The server returned an error code of 400 or higher. This code is returned only when you use the -f option or the --fail-with-body option.
-
curl: (28)The time you set, for example with the -m option or the --connect-timeout option, ran out before the request finished.
-
curl: (35)The TLS connection failed, for example when the server and curl have no TLS version or cipher in common.
-
curl: (60)The SSL certificate can't be verified against the trusted certificate authorities: a self-signed certificate, an expired certificate, or a missing certificate chain on the server.
No matching commands.
Names and addresses in the examples
The examples on this page use the example.com domain and IP addresses reserved for documentation, such as 192.0.2.10, so replace them with your own domain name and addresses. The address https://www.ereznet.co.il/ip is real and returns your public IP address.
HEAD request or GET request
The -I option sends a HEAD request, and some websites and protection systems return a different code for it than for regular browsing. When the result doesn't make sense, check the status code with a GET request using -s -o /dev/null -w "%{http_code}", or show the headers with -i. Every code is explained on the HTTP status codes page.
curl on Windows
On Windows 10 and Windows 11, the tool comes preinstalled. In CMD, you type curl, and in Windows PowerShell you type curl.exe, because there the word curl runs a different command. More commands for the Windows command line are on the CMD commands page.
With Linux hosting plans, we migrate your site to ErezNet servers at no cost, and your site stays online throughout the move. Before the DNS records are switched, you get temporary access to make sure everything works properly on the new server. For projects that need a server of their own, a Linux VPS gives you full root access over SSH.
curl commands FAQ
How do I check which status code a website returns with curl?
The curl -I https://example.com command shows the status line and the response headers. To see only the code, in a regular GET request, run curl -s -o /dev/null -w "%{http_code}" https://example.com. When there are redirects, curl -sIL shows the status code of every step in the chain, up to the final URL.
How do I test a site on a new server before changing the DNS records?
The --resolve option sends the request to the IP address of the new server, without changing DNS and without editing the hosts file, for example curl -I --resolve example.com:443:192.0.2.10 https://example.com/. The site name is sent as usual, so the new server returns the right site and the SSL certificate is checked against the domain name. When the response looks right, you can switch the DNS records with confidence.
How do I find my public IP address from the command line?
Run curl https://www.ereznet.co.il/ip, and the public address of your connection is shown on one line. The -4 and -6 options show the IPv4 address and the IPv6 address separately. On Windows, type curl.exe, and in a browser you can use the What is my IP tool.
Why does curl behave differently in PowerShell?
In Windows PowerShell, the word curl is an alias for the Invoke-WebRequest command, which has different options and output. To run curl itself, type curl.exe. The tool comes preinstalled on Windows 10 and Windows 11, and in CMD you can type curl as usual.
How do I measure how long a website takes to respond with curl?
The -w option shows the time of every stage of the request: the DNS lookup (time_namelookup), connecting to the server (time_connect), the TLS connection (time_appconnect), receiving the first byte (time_starttransfer), and the total time (time_total). A long time to the first byte usually points to slow processing on the server, and a long DNS lookup points to the DNS server.