Menu
Coddy logo textTech

Status and Timing

Lesson 29 of 47 in Coddy's Networking with the Terminal course.

-w prints facts about the transfer after it finishes, using placeholders in a format string:

curl -s -o /dev/null -w '%{http_code} %{size_download}\n' URL

The ones worth knowing:

  • %{http_code}: the status code
  • %{size_download}: bytes received
  • %{time_total}: how long the whole thing took
  • %{url_effective}: the URL finally used, after any redirects

This is what makes curl scriptable. Instead of eyeballing a page you get a number a script can test, which is how uptime checks and deployment smoke tests are usually built.

Pair it with -o /dev/null so the body does not get in the way, and remember the \n, or your output runs into the next line.

challenge icon

Challenge

Hard

Report a request as two numbers.

  1. Create index.html containing hi and serve the folder on port 9119
  2. Fetch it, discarding the body, and print the status code and the number of bytes received, separated by a space

The file is 2 characters plus a newline, so the output is:

200 3

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Networking with the Terminal

Practice on your own: Terminal playground