How to Download a File with curl in Linux
Download files with curl while preserving the remote filename and handling redirects.
curl is a flexible HTTP client as well as a download tool. For a simple file download, `-L` and `-O` solve the two common problems: redirects and choosing an output filename.
Step by step
1 Download using the remote filename
$ curl -LO https://example.com/file.zip Follows redirects and writes file.zip in the current directory.
2 Choose the output filename
$ curl -L https://example.com/file.zip -o release.zip The lowercase -o option lets you choose the local path.
3 Resume a partial download
$ curl -L -C - -o release.zip https://example.com/file.zip The -C - option asks curl to resume from the existing local file size when the server supports it.
4 Inspect headers only
$ curl -I https://example.com/file.zip A HEAD request can reveal redirects, content type and other response headers without downloading the body.
Tips worth knowing
- Use `curl -fL` in scripts when HTTP errors should produce a non-zero exit status.
- Quote URLs containing shell metacharacters.
- Verify checksums when downloading software or release artifacts.
Frequently asked questions
How do I download a file with curl?
Use `curl -LO URL` when you want to follow redirects and keep the remote filename.
What is the difference between -o and -O?
`-o` chooses the local filename; `-O` uses the remote filename.
Why does curl save an HTML page instead of my file?
Check redirects, authentication and the response headers; use `curl -I` or `curl -fL` to diagnose.
The commands behind it
Download files, test APIs, send POST requests with JSON, and inspect headers.
wgetDownload files and whole sites, resume interrupted transfers, and fetch in the background.
sha256sum & md5sumFingerprint files, verify downloads, and prove two files are identical.
More how-to guides
See how much space is left, and find out what is using it.
Extract a .tar.gz archiveUnpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.
Free a port that is already in useFind which process holds a port and stop it cleanly.
Find and replace text in filesReplace text in one file or across a whole project, safely.