curl チートシート
curl を素早く参照:HTTP メソッド、ヘッダ、認証、JSON、フォーム、アップロード、ダウンロード、リダイレクト、デバッグ、再試行、接続制御 — よく使うオプションと実用例をまとめました。
30 コマンド
基礎
curl <url>URL を取得してボディを stdout に出力します。
-L リダイレクト追跡; -i ヘッダも含める; -I HEAD のみ; -v 詳細; -s 無音; -S エラー表示; --compressed gzip/brotli をデコード
curl -L -s -o website.html https://example.com && curl -sI https://example.comcurl -O <url> / curl -o <file> <url>ファイルをダウンロード:-O はリモート名のまま、-o は指定パスへ保存。
-O; -o file; --create-dirs; --remove-on-error; -C - レジューム; --retry N; --retry-delay N
curl -O https://nodejs.org/dist/v22.17.0/node-v22.17.0-linux-x64.tar.xz && curl -C - -O https://releases.example.com/sqldump.sqlHTTP メソッド / ヘッダ
curl -X <METHOD> <url>特定の HTTP メソッド(POST / PUT / PATCH / DELETE など)を強制。
-X POST/PUT/PATCH/DELETE; --request-method; --request-target
curl -X DELETE -s https://api.example.com/users/42 && curl -X POST https://api.example.com/resetcurl -H 'Header: value' <url>1 つ以上のカスタム ヘッダを送信(Content-Type、X-API-Key など)。
-H 'X-API-Key: ...'; -H 繰り返し; --json(Content-Type + payload); --form -F(multipart)
curl -s -H 'Authorization: Bearer $TOKEN' -H 'Accept: application/json' https://api.example.com/orders/1curl -A <agent> / -e <url>User-Agent 文字列または Referer を設定します。
-A 'Mozilla/5.0 ...'; -e 'https://google.com'; --referer 別名
curl -sA 'Mozilla/5.0 (X11; Linux)' -e 'https://google.com' https://example.com/articlecurl -i / -D headers.txt / -I <url>-i でヘッダも表示、-D でファイルへ書込、-I は HEAD のみ。
-i; -D <file>; -I; --dump-header <file>
curl -sI https://api.example.com/health && curl -D headers.txt -o body.json -s https://api.example.com/me認証
curl -u <user>:<password>HTTP Basic 認証(パスワードは省略可。コロンのみだとプロンプト)。
-u user:pass; --basic; -U readonly 特定メソッド
curl -u alice:'P@ssw0rd!' -s https://rest.example.com/private/list && curl -u alice -s https://rest.example.com/mecurl -H 'Authorization: Bearer <token>'Bearer トークンを送信(--oauth2-bearer でも可)。
--oauth2-bearer $TOKEN; --bearer 別名(8+)
curl --oauth2-bearer '$GH_TOKEN' -s https://api.github.com/user | jq .logincurl --cert / --key / --cacertmTLS 用にクライアント証明書 / CA バンドルを使用します。
--cert certfile[:password]; --key key; --cacert ca.pem; --capath dir
curl --cert client.p12:P@ss --cacert ca.pem -s https://secure.internal/api && curl --cert cert.pem --key key.pem --cacert ca.pem https://...データ / フォーム
curl -d '<body>' / -d @file / --data-raw / --data-binaryリクエスト ボディを送信(POST / PUT)。-d は既定で form エンコード;--data-binary はバイトを保持。
-d 'a=b&c=d'; --data-raw; --data-binary @f; -G と --data-urlencode でクエリ文字列を構築
curl -s -X POST -d 'name=alice&[email protected]' https://api.example.com/users && curl --data-binary @body.json -H 'Content-Type: application/json' https://api.example.com/notescurl -F 'file=@/path'multipart / form-data アップロードを送信(ブラウザ標準のアップロード形式)。
-F field=value; -F file=@path; -F '[email protected];type=image/png'; --form-string 生
curl -s -F 'avatar=@./photo.png' -F 'name=alice' https://api.example.com/profilecurl -G --data-urlencodeURL エンコードされたクエリ文字列を構築(値を自動エンコード)。
-G --data-urlencode 'q=hello world' --data-urlencode 'limit=10'
curl -sG --data-urlencode 'q=hello world' --data-urlencode 'page=2' https://api.example.com/searchJSON
curl -d @body.json -H 'Content-Type: application/json'リクエスト ボディに JSON を入れて送信します。
--json ショートカット(Content-Type + ペイロードを 1 フラグで)
curl -s --json @body.json -X POST https://api.example.com/orders && curl --json '{"a":1}' https://api.example.com/xcurl | jq '.'レスポンスを jq にパイプして可読 / フィルタした JSON に整形。
jq '. | {name,id}'; jq 'select(.id==42)'
curl -s https://api.github.com/repos/pnpm/pnpm/releases/latest | jq '{tag_name: .tag_name, name: .name, assets: [.assets[].name]}'Cookie / セッション
curl -b cookies.txt / -c cookies.txtCookie の読み込み(-b)/ 書き出し(-c)。初回は -j を付けてリダイレクトを取得。
-c jar.txt 保存; -b "k=v" 文字列; -b / -c /tmp/jar 同一ファイル
curl -s -c /tmp/jar.txt -o /dev/null https://app.example.com/login && curl -s -b /tmp/jar.txt https://app.example.com/dashboardcurl --cookie-jar / --cookie-c / -b のロング フォーム別名;スクリプトでは明示的で読みやすい。
curl --cookie-jar /tmp/jar --cookie /tmp/jar -s https://app.example.com/meデバッグ
curl -v / -vv / --trace-ascii詳細ハンドシェイク トレース;--trace は送受信バイトをダンプ。
-v / -vv / -vvv; --trace-ascii file; --trace file(バイナリ)
curl -v --trace-ascii /tmp/login.trace https://api.example.com/logincurl --next連結リクエスト間でフラグをリセット('URL parm 0' や接続リークを回避)。
--next; 各呼び出しでリセット
curl -s -H 'Accept: text/html' https://example.com --next -s -H 'Accept: application/json' https://example.com/apicurl -w '%{http_code}\n'write-out テンプレートを定義 — タイミングやステータスをスクリプトから確認。
-w 'status=%{http_code} time=%{time_total}\n'; --write-out
curl -s -o /dev/null -w 'status=%{http_code} time=%{time_total}s bytes=%{size_download}\n' https://example.com/health転送 / 再試行
curl -C - <url>中断した部分ダウンロードを再開します。
-C -; --continue-at -
curl -C - -O https://releases.example.com/ubuntu-iso.isocurl --retry N --retry-delay S --retry-all-errors一時的なエラー(ネットワーク、5xx、リセット)を自動再試行。
--retry; --retry-delay; --retry-max-time; --retry-connrefused; --retry-all-errors(8+)
curl --retry 5 --retry-delay 5 --retry-all-errors --max-time 60 -O https://internal.example.com/big.zipcurl --limit-rate <speed> / --max-time <seconds>帯域使用量 / 全体の実行時間の上限を指定します。
--limit-rate 200k; --max-time 30; --connect-timeout 5
curl --limit-rate 1M --max-time 600 -O https://releases.example.com/big.isocurl -T <file> <url>PUT でファイルをアップロード(HTTP PUT / RESUMABLE は -C - と併用)。
-T file; --upload-file; -C - で再開; -H 'Authorization: ...' と併用
curl -T ./dist.tar.gz -H 'Authorization: Bearer $TOKEN' https://uploads.example.com/build/1.4.2.tar.gz接続
curl --interface <ip> / --dns-serversNIC バインド(VPN インタフェース IP 利用)や DNS 上書き — スプリット DNS デバッグに。
--interface eth0:0; --dns-servers 1.1.1.1; --resolve 'host:port:ip' で呼び出し毎上書き
curl --interface 10.99.0.1 -s https://api.internal.example.com && curl --resolve api.internal.example.com:443:127.0.0.1 -s https://api.internal.example.comcurl --http2 / --http3 / --tlsv1.2プロトコル / TLS バージョンを指定してネゴシエートします。
--http2; --http2-prior-knowledge; --http3(curl 7.88+); --tls-max 1.3; --no-alpn
curl --http3 -sI https://cloudflare-quic.com && curl --tlsv1.2 -s https://api.example.comcurl --insecure / --cacertTLS 検証を無効化 / 上書き(insecure はデバッグ専用)。
-k / --insecure; --cacert ca.pem; --capath dir
curl -k --cacert dev-ca.pem -s https://localhost:8443/health設定
curl -K config.curlcurl を設定ファイルで駆動 — 反復スクリプトに最適。
--config file; 各呼び出し毎のオプション
curl -sK - <<'EOF'\nurl = 'https://api.example.com/me'\nheader = 'Authorization: Bearer '$'${TOKEN}'\ncurl --parallel / --parallel-max1 つの curl から複数 URL を並行実行(curl 7.68+)。
--parallel; --parallel-immediate; --parallel-max N
curl --parallel --parallel-max 5 -sO https://example.com/img1.png -sO https://example.com/img2.pngその他
curl --fail-with-body / -f / -fsSLスクリプト向け定番イディオム:静かに追跡、HTTP エラーで失敗、出力。
-f / --fail; --fail-with-body エラー時もボディ表示; -s 無音; -L 追跡; -S エラー表示
curl -fsSL -o installer.sh https://get.docker.com && sh installer.shcurl --compressed / --no-compressed--compressed で gzip / deflate / brotli を要求;帯域を節約します。
--compressed
curl --compressed -s -A 'Mozilla/5.0' https://news.example.com | head -c 200チートシート バージョン 1.0.0
curl 7.88+ に対応