← Linux and the Command Line Lesson 30 of 51 · 5 XP

curl and wget — requests and downloads

Theory

Machine translation, not yet reviewed by a native speaker.

wget downloads a file:

wget https://example.com/file.zip             # saves it under the same name
wget -O app.zip https://example.com/file.zip  # under your own name
wget -c https://…/big.iso                     # resume an interrupted download

curl is a universal tool for HTTP: it's used to test APIs and websites.

curl https://api.github.com                   # print the response on the screen
curl -o page.html https://example.com         # save it to a file
curl -O https://example.com/file.zip          # save it under the name from the URL
curl -I https://example.com                   # only the response headers
curl -L http://github.com                     # follow redirects
curl -s https://…  | grep title               # -s: without the progress indicator

Requests to an API:

curl -X POST https://api.example.com/login \
     -H "Content-Type: application/json" \
     -d '{"user": "kai", "password": "secret"}'

A \ at the end of a line continues a long command on the next line.

For your platform on Django: curl -I http://127.0.0.1:8000/ is a quick check that the server responds. The code 200 means all is well, 302 — a redirect (for example, to the login page), 404 — no such page, 500 — an error in the server's code.

Never run curl … | sh from websites you haven't checked: that way you run someone else's code with your permissions.

The Linux built into the browser runs without a network, so try the networking commands on your own computer or a VPS.

Sign up for free to mark finished lessons and track your progress.