Recap: curl Flags
Lesson 31 of 47 in Coddy's Networking with the Terminal course.
The working set, worth committing to memory:
-s silent: no progress meter
-i / -I headers with the body / headers only
-o FILE save the body (-o /dev/null to discard)
-H 'K: V' add a request header
-X METHOD change the method
-w '%{...}' print facts about the transfer
--max-time N give up after N seconds
--fail exit non-zero on 4xx and 5xxTwo habits go with them. Always -s, because the progress meter goes to the error stream and ruins output. And keep status code and exit code apart: the first is the server's answer, the second is whether the conversation happened at all.
When something is unclear, put a listener in the way and read the request back. Guessing what was sent is always slower than looking.
Challenge
HardPut four flags together in one command.
- Create
index.htmlcontainingdoneand serve the folder on port 9121 - Fetch it silently, discarding the body, giving up after 5 seconds, and print the status code followed by a space and the byte count
The text is 4 characters plus a newline, so the output is:
200 5Try 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