Saving Responses
Lesson 27 of 47 in Coddy's Networking with the Terminal course.
Printing a response to the screen is fine for a line of text and useless for a file. -o saves the body to a name you choose:
curl -s -o page.html http://127.0.0.1:9117/index.htmlThere is also -O, capital, which keeps the remote file's own name. Handy, and worth being careful with, since the server chooses what lands in your folder.
The other use is deliberately throwing the body away. -o /dev/null sends it nowhere, which is exactly what you want when you only care about the status code or the timing. You have been using that already.
Once a response is a file, ordinary terminal tools apply: wc -c to count bytes, grep to search it, head to peek.
Challenge
MediumDownload to a file, then measure the file.
- Create
index.htmlcontainingsaved to disk - Serve the folder on port 9117
- Fetch it, saving the body as
copy.html - Print the byte count of
copy.html
The text is 13 characters plus a newline, so the output is:
14Try 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