linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Commands/cmd-curl

kb/commands ── Commands ── beginner

curl: HTTP client from the terminal

`curl` is a CLI for HTTP, HTTPS, FTP, and more. Send requests, inspect headers, certificates, and timing. The primary tool for REST API debugging.

view as markdownaka: http-client

Basic forms

bash
curl https://example.com                  # GET, body to stdout
curl -s https://api.example/users         # -s: silent (no progress bar)
curl -o out.html https://example.com      # save to file
curl -O https://example.com/file.tar.gz   # save with original filename
curl -X POST -d 'name=alice' https://...  # POST with form data
curl -X POST -H "Content-Type: application/json" -d '{"x":1}' https://...
curl -X DELETE https://api.example/u/123

Headers and authentication

bash
curl -H "Authorization: Bearer $TOKEN" https://api.example
curl -u user:pass https://api.example     # basic auth
curl --cookie "session=abc" https://...
curl -A "Mozilla/5.0" https://...         # User-Agent

Debug flags

bash
curl -v https://example.com               # verbose: shows request + response headers
curl -I https://example.com               # headers only (HEAD request; quick status check)
curl --trace-ascii - https://example.com  # dump of all exchanged bytes
curl -w "@curl-format.txt" -o /dev/null -s https://example.com  # timing

Format for -w:

time_namelookup:    %{time_namelookup}s
time_connect:       %{time_connect}s
time_appconnect:    %{time_appconnect}s   # TLS handshake
time_starttransfer: %{time_starttransfer}s # TTFB
time_total:         %{time_total}s

This shows exactly where the slowdown is: dns-resolution / TCP / tls-handshake / server.

TLS

bash
curl -k https://self-signed             # skip certificate verification (NOT for production!)
curl --cacert ca.pem https://...         # trust a specific CA
curl --cert client.pem --key client.key  # mTLS
curl --resolve example.com:443:1.2.3.4 https://example.com   # DNS override

--resolve is invaluable for testing. It connects to the specified IP while sending the correct SNI/Host header. No /etc/hosts edits needed.

Retries and timeouts

bash
curl --max-time 10 https://...           # overall timeout of 10 s
curl --connect-timeout 5 https://...     # TCP connect only
curl --retry 3 --retry-delay 2 https://... # auto-retry on network errors

Pipe to jq

bash
curl -s https://api.github.com/repos/torvalds/linux | jq '.stargazers_count'

The standard combination for REST debugging.

§ команды

bash
curl -I https://example.com

Response headers only. Quick check of status, redirects, and HTTP version.

bash
curl -v -o /dev/null -s https://example.com 2>&1 | grep -E '^[<>]'

Clean dump of request/response headers (no body).

bash
curl -X POST -H 'Content-Type: application/json' -d @body.json https://api.example

POST with JSON from a file (@filename reads the file contents).

bash
curl --resolve api.test:443:127.0.0.1 https://api.test/health

Override DNS resolution for testing without touching /etc/hosts.

bash
curl -w '%{time_total}s\n' -o /dev/null -s https://example.com

Total request time. Use to measure latency.

§ см. также

  • cmd-jqjq: JSON queries and transformationjq is a query language for JSON in the shell. Use .field, .array[], select(...), map(...), and in-expression pipes via |. -r strips quotes, -c packs output into a single line. Works well in curl + jq + grep pipelines.
  • tls-handshakeTLS HandshakeTLS is the encryption layer above TCP. Before data flows, both sides run a handshake: they exchange keys, verify the certificate, and agree on a cipher.
  • http-protocolHTTP/1.1, HTTP/2, HTTP/3HTTP/1.1 is a text-based protocol with keep-alive. HTTP/2 is binary with multiplexing over a single TCP connection. HTTP/3 carries HTTP/2 semantics over QUIC/UDP without TCP head-of-line blocking.
  • http2-internalsHTTP/2: Binary Framing, HPACK, Stream MultiplexingHTTP/2 is binary multiplexing over a single TCP connection. HPACK compresses headers through an indexed dictionary. Streams are independent. Server push is deprecated. On a loss-prone link, HoL blocking is a real problem, solved by QUIC.
  • websocketWebSocket: Bidirectional Channel over HTTPWebSocket is a bidirectional channel over a single TCP connection. The upgrade from HTTP/1.1 uses the Upgrade header; after that, both sides exchange binary frames. Typical use cases: real-time UI, chats, dashboards, live updates.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies