A command-line task may call for checking a web response or sending data to a service. The curl command transfers data to or from URLs.
This article walks through inspecting response headers and sending a small JSON request with curl.
TL;DR: curl command in Linux
curl handles transfers from a URL. These options determine whether content goes to a file, the terminal or the request body.
- Fetch: curl https://example.com/
- Save to a chosen name: curl -o page.html https://example.com/
- Follow redirects: add -L.
- Inspect response headers: use -I for a HEAD request or -i to include headers with the body.
What is the curl command in Linux?
curl transfers data to or from URLs. Its libcurl library lets applications perform those transfers. The basic command accepts options and a URL.
curl --version
For a Linux install check, use the command shown above. It reports build and capability details.
curl 8.5.0 (aarch64-unknown-linux-gnu) libcurl/8.5.0 OpenSSL/3.0.13 zlib/1.3 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.7 libpsl/0.21.2 (+libidn2/2.3.7) libssh/0.10.6/openssl/zlib nghttp2/1.59.0 librtmp/2.3 OpenLDAP/2.6.10
Release-Date: 2023-12-06, security patched: 8.5.0-2ubuntu10.16
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd

I checked this output to confirm which protocols and features this curl build provides.
How to use the curl command in Linux step by step
Use a small request first, then add an option for a specific transfer need. Replace the example host with a URL you may access.
- A shell where curl is available
- A network connection when the URL is remote
- A destination you have permission to access
Step 1: Fetch a URL
It returns the resource content to the terminal or a file.
curl https://example.com/
The response contains the resource itself, not a browser-rendered page. Save a large or binary response to a file rather than displaying it in the terminal.
Step 2: Download a file with a chosen name
For downloads, lowercase -o selects a filename and uppercase -O uses the URL filename. Check the destination before overwriting an existing file.
curl -L -o page.html https://example.com/
Here, -L follows redirects and -o writes the response to page.html. Use -O when a URL names a downloadable file, such as curl -L -O https://example.com/archive.tar.gz.
Step 3: Inspect response headers
Use -I to request headers with a HEAD request. Use -i to include response headers with the body. Some servers treat HEAD differently from GET.
curl -I https://example.com/
curl -i https://example.com/
Choose -I when you need metadata only and the server accepts HEAD. Choose -i when you need the body too.
Step 4: Send a small JSON request
Use -H to set a request header and -d to send a body. With HTTP, -d defaults to a POST request . The API defines what that request changes.
curl -H 'Content-Type: application/json' \
-d '{"name":"Ada"}' \
https://api.example.com/users
Only send data to an endpoint whose request format and effects you understand. Do not put passwords or access tokens directly into a command that may be saved in shell history.
What should you check when curl does not work?
A curl transfer can succeed even when the server returns an HTTP error status. Check the response status separately from curl’s own exit status, then choose flags that make the behavior explicit.
| Symptom | What to check | Next step |
|---|---|---|
| Command not found | Whether curl is installed | Use your distribution’s documented package manager and package name |
| Only a redirect response appears | Response includes a Location header | Add -L to follow it |
| HTTP 404 or 500 but command exits successfully | HTTP status versus transfer result | Use --fail-with-body to return a failure for HTTP errors while keeping the body |
| Certificate verification error | System trust store and server certificate | Fix the trust or certificate issue. Do not disable verification with -k for routine use |
The -sS pair hides the progress meter but still shows errors. Add -w ‘\n%{http_code}\n’ when you need the HTTP status printed after a request. Avoid -k as a workaround because it skips certificate checks.
For an interrupted download, -C – can resume when the server supports byte ranges and the partial file remains available. Use curl -C – -O URL with the same URL and local filename. A server that does not support resuming may reject the request.
Quote URLs that contain ampersands to prevent the shell from treating them as background operators. Spaces or wildcard characters in query values need similar care.
curl 'https://example.com/search?q=linux&page=2'
Set a connection timeout and a total transfer limit for scripts that cannot wait indefinitely.
curl --connect-timeout 10 --max-time 30 https://example.com/
Choose a limit that fits the transfer. A short timeout can interrupt a slow download.
For retrieving files, you can also use the wget command in Linux. Choose curl when you need direct control over an HTTP request or its response, then use the Linux commands cheat sheet for other shell tasks.
Use the option that matches the transfer task. Verify server support before sending credentials or files.
| Task | Option | What to know |
|---|---|---|
| Transfer speed | --limit-rate 500K | The transfer-rate flag caps speed with values such as 500K. See the official manual for protocol details. |
| HTTP authentication | -u username | Supply credentials only through an approved secure method, not a literal password in shell history |
| Upload a file | -T local-file | Requires a server and protocol that accept uploads |
Confirm the destination and supported method before an upload. For authentication, use a secure method accepted by the service rather than placing a password in shell history.
Conclusion: Use curl for direct URL transfers
Use -L -o filename URL for a chosen name, or -L -O URL to use the URL’s name. Check for an existing local file first.
For the complete option reference, see the official curl man page and the curl HTTP scripting guide.
FAQ
curl has a few common options that answer recurring questions.
What does the curl command do in Linux?
It transfers data to or from a URL using protocols such as HTTP and HTTPS. It can print a response, save a file, inspect headers or send request data.
How do I download a file with curl?
Use curl -L -o filename URL to follow redirects and save the response under a chosen name. Use uppercase -O to take the name from the URL.
How can I check whether curl is installed?
Run curl –version. The command prints the installed curl version and its supported protocols and features.
