What is cURL?
The command line is a screen where you type commands. cURL lets you talk to a website from there. It can download a file, check if a site is up, or send data to a web address. It works like a browser that has no pictures.
Check that cURL is installed
Open a terminal. On Windows 10 and later, use Command Prompt. Type:
curl --version
This prints the cURL version. If it is missing on Ubuntu, install it with sudo apt install curl.
Basic commands
- Show a web page's code:
This command prints the page source on your screen.curl https://example.com - See only the headers:
Headers are short notes the server sends before the page. The first line shows the status, such ascurl -I https://example.com200 OK. - Save a file with its own name:
curl -O https://example.com/file.zip - Save a file with a name you choose:
curl -o mycopy.zip https://example.com/file.zip - Follow a redirect:
A redirect sends you from one address to another. Thecurl -L http://example.com-Loption tells cURL to follow it. - Show details of the connection:
Thecurl -v https://example.com-vstands for verbose. It prints every step and is great for fixing problems.
Send data
curl -X POST -d "name=Sam" https://example.com/form
This command sends the text name=Sam to a web address, like a filled-in form.
Handy status codes
| Code | Meaning |
|---|---|
| 200 | All good |
| 301 or 302 | The page moved |
| 403 | Not allowed |
| 404 | Page not found |
| 500 | Server error |
Tip: Use quotes around web addresses that contain
& or ?. Otherwise the terminal may misread them.Quick recap
- cURL fetches web content from the command line.
curl -Ishows headers.curl -Odownloads a file.curl -Lfollows redirects.curl -vhelps you find problems.