The command
curl -fLO https://example.com/files/report.pdf
What the flags do
| Flag | What it does |
|---|---|
-O | Save under the filename from the URL. Long form: --remote-name. |
-o name | Save under a name you choose. |
-L | Follow redirects. Download links very often redirect. |
-f | Fail on HTTP errors rather than saving the error page. |
-C - | Resume a partial download from where it stopped. |
--limit-rate 2M | Cap the transfer speed. |
Naming the file
-O uses the last segment of the URL as the filename; -o lets you set it, including a path. If the URL has no useful final segment, for instance a download endpoint with an id in the query string, combine -O with -J and curl takes the name from the server's Content-Disposition header. --create-dirs makes any missing directories in an -o path.
curl -fL -o tools/report-2026.pdf --create-dirs https://example.com/files/report.pdf
curl -fLOJ "https://example.com/download?id=8841"
# several files in one command, reusing the connection
curl -fL -O https://example.com/a.zip -O https://example.com/b.zip
Downloads you can rely on
Three flags belong on almost every scripted download. -L, because release assets and CDN links redirect and without it you save a few bytes of redirect body. -f, because otherwise a 404 page is written to disk under the name of the file you wanted and the script carries on. And -C - when the file is large: curl looks at the size of the partial file and asks the server for the remainder with a Range request.
Verify what you got. A download finishing without error says nothing about whether the content is what the publisher intended.
curl -fL -C - -O https://example.com/big.iso # rerun to resume
sha256sum big.iso # compare with the published checksum
Common mistakes
- Resuming needs server support. If the server ignores
Range, curl reports that it cannot resume, and you start again. -Oon a URL ending in a slash fails because there is no filename to use. Give one with-o.- Piping a download into a shell (
curl ... | sh) runs whatever arrives, including a truncated script. Download, inspect, then run.
Related curl examples
Curl Follow Redirect Example
Curl does not follow redirects unless asked.
Curl Timeout Example
By default curl puts no limit on how long a transfer may take, so one silent server can hang a script indefinitely.
Curl POST File Example
There are three different things people mean by "post a file", and they are three different requests.
Wget vs Curl
Both fetch things from URLs and both are probably on your machine.
All Curl Examples
49 worked examples, grouped by what you are trying to do.
More under Network behaviour
References
- curl man page: -O — Saving a download under its remote name.
- curl man page: -C — Resuming an interrupted transfer.
These links leave api-tester.com, which is independent of the projects they point to.
FAQ
How do I download a file with curl?
Use curl -O URL to save it under its remote filename, or curl -o name URL to choose the filename. Add -L to follow redirects.
How do I resume a download with curl?
Run the same command with -C - added. Curl checks the partial file size and requests only the remaining bytes.
What is the difference between curl -o and -O?
Lowercase -o takes a filename you specify. Uppercase -O takes no argument and uses the filename from the URL.