Lesson 6.1

Fetching with curl and wget

8 minutes

Your terminal isn’t just for working with local files — it can also reach out to the internet and pull data back. Two commands handle this: curl and wget. You’ll see AI tools use both of them regularly.

curl – Fetch and Display

The curl command fetches content from a URL and, by default, prints it straight to your terminal.

curl https://api.example.com/status

This hits the URL and shows whatever comes back — often JSON data, HTML, or plain text.

Try it now:

curl https://api.example.com/status

Saving to a File

Most of the time, you don’t just want to see the data — you want to save it. The -o flag (lowercase “o”) lets you specify a filename:

curl -o data.json https://api.example.com/users

This downloads the content and saves it to data.json instead of printing it to the screen.

Try it now:

curl -o users.json https://api.example.com/users

Then check the file with cat users.json to see what you downloaded.

Silent Mode

By default, curl shows a progress bar and transfer stats. The -s flag (silent) suppresses all that noise:

curl -s https://api.example.com/status

This gives you just the content, nothing extra. Useful when you’re piping output into other commands or just want clean results.

curl Quick Reference
curl URL -- fetch and display content
curl -o file URL -- download and save to a file
curl -s URL -- fetch silently (no progress bar)

wget – Download Files

While curl defaults to printing content on screen, wget defaults to saving files. It’s designed for downloading.

wget https://api.example.com/users

This downloads the content and automatically saves it with a filename based on the URL (in this case, users).

Custom Filenames

Use the -O flag (uppercase “O”) to choose a name for the downloaded file:

wget -O users.json https://api.example.com/users

Try it now:

wget -O users.json https://api.example.com/users

Then run ls -l users.json to confirm the file was created.

curl vs. wget

Both tools fetch data from the internet, but they have different defaults:

Command Default behavior Best for
curl URL Prints to screen Quick lookups, API calls, piping data
wget URL Saves to file Downloading files you want to keep

You don’t need to memorize which is “better” — they overlap a lot. Just know that when your AI tool uses either one, it’s reaching out to the internet to grab something.

When AI Tools Use These Commands

AI coding assistants use curl and wget constantly. Here are the most common scenarios:

  • Installing packages or tools: curl -fsSL https://get.docker.com | sh
  • Fetching configuration files: wget -O .eslintrc https://example.com/config
  • Calling APIs: curl -s https://api.github.com/repos/owner/repo
  • Downloading dependencies: wget https://releases.hashicorp.com/terraform/1.5.0/terraform_1.5.0_linux_amd64.zip
Security note: Be careful with commands that pipe a URL directly into a shell, like curl URL | sh. This downloads a script and immediately runs it without you seeing what's inside. Always check what you're downloading before executing it. A safer approach is to download first (curl -o script.sh URL), read it (cat script.sh), and then run it.

Practice

Try these commands in the terminal:

  1. curl https://api.example.com/status – see what comes back
  2. curl -o status.json https://api.example.com/status – save it to a file
  3. cat status.json – verify the contents
  4. wget -O users.json https://api.example.com/users – download with a custom name
  5. ls -l users.json – check the downloaded file
BlueBox Terminal