Home·Terminal commands

curl

Networking

Usage

curl [options] <url>

Fetches a URL and prints the body to the terminal; unlike a browser it does not follow redirects without `-L`, so a 301 looks like an empty response.

Common flags

FlagMeaning
-LFollow redirects. curl does not follow them on its own, unlike a browser.
-iPrint the response headers along with the body; -I sends HEAD and prints headers only.
-d '{"a":1}'Send a request body. This alone already means POST.
-H "Content-Type: application/json"Add a request header; repeat -H for more.
-X PUTOverride the method. Unnecessary with -d, which is already a POST.
-o <file> / -OSave the body to a file / save it under the remote filename.
-s / -sSNo progress meter / silent but still print errors.
-fExit nonzero on HTTP 4xx and 5xx instead of printing the error page.
-kSkip certificate verification. Debugging only, never in production.

Examples

curl -fsSL https://example.com/install.sh -o install.sh

Download quietly, follow redirects, fail loudly on a 404.

curl -i -H "Content-Type: application/json" -d '{"name":"a"}' https://api.example.com/items

POST JSON and read the response headers.

curl -s -o /dev/null -w "%{http_code}\n" https://example.com

Print just the status code.

When a connection fails, these narrow down how far it got — name not resolving, no route, or a blocked port.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does curl do?

Fetches a URL and prints the body to the terminal; unlike a browser it does not follow redirects without `-L`, so a 301 looks like an empty response.

Q. How do I type it?

curl [options] <url> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

9 are listed here; the full set is in man curl. This command sits under Networking.

Related commands

man page: man curl