curl -O https://example.com/file.zipDownload a file, keeping its name.
When to use it
Use curl to download files, test APIs, check redirects and headers, or reproduce what an app sends. macOS 15 includes curl 8.7.
Steps
Fetch a page
Prints the body to the terminal.curl https://example.comDownload a file
-O keeps the remote file name; -o sets your own; -L follows redirects; -C - resumes.curl -L -O -C - https://example.com/big.isoSend JSON to an API
--json sets Content-Type and Accept for you and sends a POST.curl --json '{"title":"Hello"}' https://api.example.com/postsAdd headers and authentication
-H adds a header; -u does Basic auth.curl -H "Authorization: Bearer $TOKEN" https://api.example.com/meUpload a form or file
-F sends multipart/form-data, like an HTML upload form.curl -F "file=@photo.jpg" https://example.com/uploadCheck status codes and headers
-I shows headers only; -w prints the status code; --fail makes curl exit non-zero on HTTP errors, useful in scripts.curl -s -o /dev/null -w '%{http_code}\n' https://example.com
Output explained
curl prints the response body to standard output and progress or errors to standard error. Exit codes tell scripts what happened: 0 success, 6 couldn't resolve host, 7 couldn't connect, 22 HTTP error with --fail, 28 timeout, 35/60 TLS problems.
-w variables you'll reuse: %{http_code}, %{size_download}, %{time_total}, %{url_effective} (after redirects), %{remote_ip}.
Options and variations
| Flag | Meaning | Example |
|---|---|---|
| -L | Follow redirects | curl -L http://example.com |
| -o FILE / -O | Save to FILE / remote name | curl -o page.html https://example.com |
| -X METHOD | HTTP method | curl -X DELETE https://api.example.com/items/1 |
| -d DATA | Send form data (implies POST) | curl -d 'q=mac' https://example.com/search |
| --json DATA | Send JSON (sets headers) | curl --json @body.json URL |
| -H 'K: V' | Add a header | curl -H 'Accept: application/json' URL |
| -u USER:PASS | Basic authentication | curl -u admin:secret URL |
| --fail-with-body | Fail on HTTP errors but keep the body | curl --fail-with-body URL |
| -s / -S | Silent / still show errors | curl -sS URL |
| --max-time N | Give up after N seconds | curl --max-time 10 URL |
Common errors
| Error | Cause | Fix |
|---|---|---|
| curl: (6) Could not resolve host | DNS or a typo; often unquoted URLs in zsh | Quote the URL; check DNS. |
| zsh: no matches found | zsh treats ? and * as globs | Wrap the URL in single quotes. |
| curl: (60) SSL certificate problem | Untrusted certificate (often a proxy) | Add the right CA with --cacert; avoid -k. |
Do it in the app
LightAtom's connections view shows curl's connections and bytes live, handy when a download seems stuck.
Frequently asked questions
Is curl installed on a Mac?
Yes. macOS includes curl (8.7.1 on macOS 15). Homebrew offers a newer build if you need the latest features.
How do I download a file with curl?
curl -L -O URL downloads it with its original name and follows redirects. Use -o name to choose the file name.
How do I send a POST request with curl?
For JSON: curl --json '{"a":1}' URL. For form data: curl -d 'a=1&b=2' URL. For file uploads: curl -F 'file=@path' URL.
What is the difference between curl and wget?
curl is a flexible tool for single requests and APIs, built into macOS. wget focuses on downloading, including whole sites recursively, and needs Homebrew on a Mac.