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' URLThe 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
HardReport a request as two numbers.
- Create
index.htmlcontaininghiand serve the folder on port 9119 - 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 3Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Networking with the Terminal
6curl in Depth
Seeing the HeadersSaving ResponsesCustom HeadersStatus and Timingcurl Exit CodesRecap: curl FlagsPractice on your own: Terminal playground