Download a file
Saves a URL's response body to a chosen local file and follows any redirects along the way, since curl doesn't follow them by default.
Last updated
curl -L -o output.zip https://example.com/file.zip
How it works
-o output.zip writes the response body to that file instead of curl's default behavior of dumping the raw bytes straight to your terminal, which is unreadable and often disruptive for anything binary. -L makes curl follow HTTP redirects — a huge share of file-hosting and CDN links respond with a 301/302 pointing at the real object storage URL, and curl does NOT follow those automatically without this flag.
Without -L, a redirected URL downloads only the tiny redirect response itself (a few bytes of HTML or nothing at all), not the actual file — it's easy to think the download "worked" because curl exits cleanly, so always include -L unless you've confirmed the link is a direct, non-redirecting URL.
Watch out for
- →-O (capital, no filename argument) is a shortcut that saves under the remote server's own filename instead of one you choose — convenient for quick downloads, but risky if the URL doesn't end in a clean, predictable filename.
- →curl doesn't resume a partial or interrupted download by default; add -C - to resume from where a previous attempt left off, provided the server supports HTTP range requests.
- →A failed download (404, expired link) still writes an output file by default, containing whatever error page the server returned — add -f (--fail) to make curl exit with an error and skip writing the file on an HTTP failure status instead.