Linux command list

curl command: make HTTP requests from the terminal

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying curl. Nothing here can touch your real files.
user@webterm:~/project$
 

curl fetches a URL from the terminal. Learn how `-I` shows just the headers, how `-o` and `-O` save to a file, and how `-X`, `-d` and `-H` call an API, by running the commands in a real terminal in your browser.

Updated: 2026-09-11

Syntax

curl [options] URL

It requests the URL and prints what comes back.

Try it first

$ curl https://example.com
<!DOCTYPE html>
<html>
<head>
    <title>Example Domain</title>
</head>
<body>
    <h1>Example Domain</h1>
    <p>This domain is for use in illustrative examples in documents.</p>
    <!-- This is a simulated response from WebTerm -->
</body>
</html>

The HTML comes back as it is. The terminal on this page never leaves the browser; it composes the response itself, which the last comment line marks. The commands and the way you read the results are the same as on a real machine.

Headers only

When the body is not the point, use -I.

$ curl -I https://example.com
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Date: Mon, 07 Sep 2026 08:38:21 GMT
Server: WebTerm/1.0 (Simulated)
Content-Length: 250

The first line is the answer. For "is the site up" and "is it redirecting", this is the fastest question you can ask.

Saving to a file

-o saves under a name you pick.

$ curl -o page.html https://example.com
$ ls
page.html  README.md
$ head -3 page.html
<!DOCTYPE html>
<html>
<head>

Nothing is printed while it saves. -O (capital) keeps the name from the URL.

$ curl -O https://example.com/app.tar.gz
$ ls
app.tar.gz  page.html  README.md

Calling an API

-s drops the progress output, which leaves clean JSON.

$ curl -s https://api.example.com/users
[
  {
    "id": 1,
    "name": "alice",
    "email": "alice@example.com"
  },
  {
    "id": 2,
    "name": "bob",
    "email": "bob@example.com"
  }
]

To send something, -X sets the method and -d carries the body. Send JSON with only those two, though, and many APIs turn it away.

$ curl -X POST -d '{"name":"ada"}' https://api.example.com/users
{
  "error": "Content-Type must be application/json"
}

Without a header, curl labels the body as form data. Declare that it is JSON with -H 'Content-Type: application/json'.

$ curl -X POST -H 'Content-Type: application/json' -d '{"name":"ada"}' https://api.example.com/users
{
  "id": 3,
  "name": "ada"
}

Other headers, such as authentication, go in -H too.

$ curl -H 'Authorization: Bearer TOKEN' https://api.example.com/me
{
  "id": 1,
  "name": "alice",
  "email": "alice@example.com"
}

Repeat -H as many times as you need.

When you actually reach for it

curl is what you type to find out whether the application answers.

SituationWhat to type
Check a site is upcurl -I https://example.com
Read an API responsecurl -s https://api.example.com/users
Send datacurl -X POST -d '...' -H 'Content-Type: application/json' URL
Call an authenticated endpointcurl -H 'Authorization: Bearer TOKEN' URL
Download a filecurl -O https://example.com/app.tar.gz

Prove the path with ping, prove the application with curl. Those two steps separate a network problem from an application problem.

Things that trip people up

Quote the URL. A URL containing ? or & is read by the shell first. Write curl 'https://api.example.com/users?page=2&limit=10'.

-o means no output on screen. If it looks like nothing happened, check ls for the file.

-X POST alone does not make it JSON. The format is declared in a header. Without -H 'Content-Type: application/json', the other side may not parse the body.

Do not type secrets directly. They stay in your shell history. Keep the token in an environment variable and pass -H "Authorization: Bearer $TOKEN".

Practise it hands-on

webterm.appthis site

  • Advanced Terminal Commands

    Learn commands for specific situations

    Try the tutorial

learn.webterm.appa separate site

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.

See the course

Related commands

ping / ssh / cat / tee

Frequently asked questions

What is the difference between -o and -O?
`-o page.html` saves under the name you choose; `-O` (capital) saves under the last part of the URL.
Why did nothing appear on screen?
With `-o` or `-O` the body goes to a file instead of the screen. Check with `ls`.
I only want the status code.
`curl -I URL` fetches just the headers, and the first line reads like `HTTP/1.1 200 OK`. No body is downloaded.
How do I POST JSON?
`curl -X POST -d '{"name":"ada"}' -H 'Content-Type: application/json' URL`. `-X` is the method, `-d` is the body, `-H` adds a header.
How does this compare with wget?
curl is for composing one request and reading the answer; wget is for downloading files. APIs are curl's territory.