AI Hints
Home›Linux Tutorial›Networking Basics
Linux · Lesson 93 of 120

curl and wget

The web from the terminal.

⏱ 2 min read▶ Video at 2:04:05🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

You don't need a browser to talk to websites. From the terminal, curl and W get can fetch any web page, or download any file. They're essential on servers, where there's no browser at all.

curl and wget
From the video: curl and wget
  • No browser needed
  • Fetch pages, download files
  • Essential on servers

Curl prints a page

Curl fetches a web address, and prints what comes back. For a web page, that's the HTML code. It's long, so here we pipe it into grep, to pick out just the title. Example domain.

Terminal
curl -s https://example.com | grep -o "<title>.*</title>"
<title>Example Domain</title>

W get saves a file

W get is made for downloading. It saves what it fetches straight into a file. Dash Q keeps it quiet, and dash capital O picks the file name. LS dash L shows the downloaded page. Curl can save files too, with dash O.

Terminal
wget -q https://example.com -O page.html
ls -l page.html
-rw-r--r-- 1 sam sam 577 Jan  5 09:00 page.html

Curl for APIs

Curl is also how developers test web APIs. Dash capital I shows just the response headers, including the status code, like two hundred for OK. Dash capital X picks the method, like post. And dash H adds headers. If you work with web apps, you'll use curl every day.

keyvalue
curl URLprint the response
curl -I URLheaders only
curl -o file URLsave to a file
wget URLdownload a file

Summary

Curl prints what a web address returns, and W get downloads files. Both work great on servers. Next, SSH, logging in to other computers.

Key takeaways
  • curl -s URL
  • wget -O file URL
  • curl -I for headers
Next up: SSH: Remote Login — controlling another computer