How to Transfer Data with the Linux curl Command

Published 2026-08-05 · Learn Linux

The curl command transfers data to and from a server. curl https://example.com fetches a page and prints it, and curl -I https://example.com shows only the HTTP headers. It is the go-to tool for testing APIs and downloading from scripts.

Fetch a page

The plainest form prints the response body to the terminal. For a page with lots of HTML, you usually save it instead.

$ curl https://example.com

Save the output with -o

Use -o to write the body to a file. This downloads a file to a chosen name.

$ curl -o page.html https://example.com

Inspect headers with -I

The -I flag sends a HEAD request and prints only the response headers: status code, content type, size and caching rules. This is the quickest health check for a server.

$ curl -I https://example.com

Test an API with -X and -d

curl defaults to GET. Choose a method with -X and send data with -d. A typical POST request looks like this:

$ curl -X POST -d "name=alice" https://api.example.com/users

curl vs wget

curl is the better fit for APIs, custom headers and methods; wget excels at plain downloads and mirrors. See curl for the full reference.

Keep learning

Related guides: How to Download Files with the Linux wget Command · How to Query DNS with dig and nslookup · How to Test Network Connectivity with ping. Read all tutorials on the Learn Linux blog.