curl vs wget の違いと使い分け|どちらを使うべきか徹底比較
- 作成日 2026.07.01
- linux
curl https://example.com/file.zip -o file.zip
wget https://example.com/file.zip
どちらもURLからデータを取得するコマンドですが、設計思想が異なります。結論を先に言うと、
- API を叩く・データを送信する →
curl - ファイルをダウンロードする → どちらでも(
wgetの方がシンプル) - 再帰的にサイトをダウンロードする →
wget
本記事ではこの使い分けを詳しく解説します。
目次
結論:先に答えを出す
| 用途 | 推奨 | 理由 |
|---|---|---|
| REST API を叩く | curl | POST・ヘッダー・認証など HTTP 機能が豊富 |
| ファイルをダウンロード | どちらでも | wget の方がシンプルに書ける |
| サイトを丸ごとダウンロード | wget | 再帰ダウンロード機能がある |
| スクリプトに組み込む | curl | 終了コードが細かく・エラー処理がしやすい |
| リトライを自動化したい | wget | デフォルトでリトライ機能がある |
| レスポンスを変数に入れたい | curl | 標準出力への出力がシンプル |
| プロキシを使う | どちらでも | 両方対応 |
基本的な違い
設計思想
curl → データ転送ツール(送受信両方・多プロトコル対応)
wget → ファイルダウンロードツール(受信特化・再帰取得が得意)
対応プロトコル
| プロトコル | curl | wget |
|---|---|---|
| HTTP / HTTPS | ✅ | ✅ |
| FTP / FTPS | ✅ | ✅ |
| SFTP / SCP | ✅ | ❌ |
| SMTP / POP3 / IMAP | ✅ | ❌ |
| LDAP | ✅ | ❌ |
| WebSocket | ✅ | ❌ |
curl の方がプロトコルの対応範囲が広く、HTTP以外の通信にも使えます。
デフォルトの出力先
# curl:デフォルトで標準出力に出力
curl https://example.com # → 画面に表示
curl https://example.com -o file.html # → ファイルに保存
# wget:デフォルトでファイルに保存
wget https://example.com # → index.html に保存
wget -O - https://example.com # → 標準出力に出力
ファイルのダウンロード
基本のダウンロード
# curl
curl -O https://example.com/file.zip # URL のファイル名で保存
curl -o myfile.zip https://example.com/file.zip # ファイル名を指定
# wget
wget https://example.com/file.zip # URL のファイル名で保存
wget -O myfile.zip https://example.com/file.zip # ファイル名を指定
進捗表示
# curl(デフォルトで進捗バーあり)
curl -O https://example.com/large.zip
# 出力例
# % Total % Received % Xferd Average Speed Time
# 100 100M 100 100M 0 0 10.0M 0 0:00:10
# wget(デフォルトで進捗バーあり)
wget https://example.com/large.zip
# 出力例
# large.zip 100%[==========] 100M 10.0MB/s in 10s
途中からのダウンロード再開(レジューム)
# curl(-C - でレジューム)
curl -C - -O https://example.com/large.zip
# wget(-c でレジューム。こちらの方がシンプル)
wget -c https://example.com/large.zip
複数ファイルを同時にダウンロード
# curl
curl -O https://example.com/file1.zip \
-O https://example.com/file2.zip \
-O https://example.com/file3.zip
# または xargs で並列ダウンロード
cat urls.txt | xargs -P 4 -I {} curl -O {}
# wget(直列で順番にダウンロード)
wget https://example.com/file1.zip \
https://example.com/file2.zip
# wget(ファイルリストからダウンロード)
wget -i urls.txt
リトライ
# curl(--retry でリトライ回数を指定)
curl --retry 3 --retry-delay 5 -O https://example.com/file.zip
# --retry-connrefused:接続拒否でもリトライ
curl --retry 5 --retry-connrefused -O https://example.com/file.zip
# wget(デフォルトで20回リトライ。-t で回数変更)
wget -t 3 https://example.com/file.zip
wget -t 0 https://example.com/file.zip # -t 0 で無限リトライ
ファイルのダウンロードでリトライが必要な場合は wget の方が設定が少なくて済みます。
HTTP リクエストの送信
ここが curl が圧倒的に得意な領域です。
GET リクエスト
# curl
curl https://api.example.com/users
# wget
wget -q -O - https://api.example.com/users
POST リクエスト(curl が圧倒的に書きやすい)
# curl:JSON を POST
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "alice@example.com"}'
# curl:フォームデータを POST
curl -X POST https://example.com/form \
-d "username=alice&password=secret"
# curl:ファイルをアップロード
curl -X POST https://api.example.com/upload \
-F "file=@/path/to/file.jpg"
# wget で POST(-d で指定、--method は wget 1.12以降)
wget -q -O - --method=POST \
--header="Content-Type: application/json" \
--body-data='{"name": "Alice"}' \
https://api.example.com/users
ヘッダーの送信
# curl(-H で複数指定可能)
curl -H "Authorization: Bearer TOKEN" \
-H "Accept: application/json" \
-H "X-Custom-Header: value" \
https://api.example.com/data
# wget(--header で指定)
wget --header="Authorization: Bearer TOKEN" \
--header="Accept: application/json" \
-q -O - https://api.example.com/data
レスポンスヘッダーの確認
# curl(-I でヘッダーのみ取得)
curl -I https://example.com
# curl(-v で詳細を表示)
curl -v https://example.com 2>&1 | head -30
# wget(--server-response でヘッダーを表示)
wget --server-response -q -O /dev/null https://example.com
認証
Basic 認証
# curl
curl -u username:password https://api.example.com/data
# wget
wget --user=username --password=password https://api.example.com/data
Bearer トークン(API キー)
# curl
curl -H "Authorization: Bearer YOUR_TOKEN" https://api.example.com/data
# wget
wget --header="Authorization: Bearer YOUR_TOKEN" \
-q -O - https://api.example.com/data
Cookie
# curl(Cookie を送信)
curl -b "session=abc123; user=alice" https://example.com
# curl(Cookie をファイルから読み込み・保存)
curl -c cookies.txt -b cookies.txt https://example.com/login
# wget(Cookie を送信)
wget --header="Cookie: session=abc123" -q -O - https://example.com
# wget(Cookie を保存・再利用)
wget --save-cookies cookies.txt \
--load-cookies cookies.txt \
--keep-session-cookies \
https://example.com/login
リダイレクト
# curl(デフォルトはリダイレクトを追わない)
curl https://example.com # 301/302でも止まる
# curl(リダイレクトを追う)
curl -L https://example.com # -L または --location
# wget(デフォルトでリダイレクトを追う)
wget https://example.com # 自動でリダイレクト先に移動
# リダイレクト回数の制限
curl -L --max-redirs 5 https://example.com
wget --max-redirect=5 https://example.com
SSL/TLS
# 証明書エラーを無視(開発環境用・本番では使わない)
curl -k https://self-signed.example.com
curl --insecure https://self-signed.example.com
wget --no-check-certificate https://self-signed.example.com
# クライアント証明書を使う
curl --cert client.pem --key client.key https://example.com
# CA 証明書を指定
curl --cacert /path/to/ca.pem https://example.com
プロキシ
# curl
curl -x http://proxy.example.com:8080 https://api.example.com/data
curl --proxy http://user:pass@proxy.example.com:8080 https://api.example.com/data
# wget
wget -e "https_proxy=http://proxy.example.com:8080" https://api.example.com/data
# 環境変数で設定(curl・wget 両方対応)
export http_proxy=http://proxy.example.com:8080
export https_proxy=http://proxy.example.com:8080
curl https://api.example.com/data
wget https://api.example.com/data
タイムアウト
# curl
curl --connect-timeout 10 https://example.com # 接続タイムアウト(秒)
curl --max-time 30 https://example.com # 全体のタイムアウト(秒)
curl --connect-timeout 10 --max-time 60 https://example.com
# wget
wget --timeout=30 https://example.com # 全体のタイムアウト
wget --connect-timeout=10 https://example.com # 接続タイムアウト
再帰的なダウンロード(wget のみ)
wget には curl にないサイトを丸ごとダウンロードする機能があります。
# サイトを再帰的にダウンロード
wget -r https://example.com
# ミラーリング(再帰・タイムスタンプ・無限深さ)
wget -m https://example.com
# 深さを制限(-l でレベル数を指定)
wget -r -l 2 https://example.com # 2階層まで
# ドメイン外のリンクは辿らない
wget -r --no-parent https://example.com/docs/
# 特定の拡張子だけダウンロード
wget -r -A "*.pdf,*.zip" https://example.com
# 特定の拡張子を除外
wget -r -R "*.jpg,*.png" https://example.com
# オフラインで見られるようにダウンロード
wget -m -k -p https://example.com
# -k:リンクをローカル参照に変換
# -p:ページ表示に必要なファイル(CSS・画像等)も取得
スクリプトでの活用
レスポンスを変数に格納する
# curl(シンプルに変数に入れられる)
RESPONSE=$(curl -s https://api.example.com/users)
echo "$RESPONSE" | jq '.name'
# wget(-q -O - で標準出力に出力)
RESPONSE=$(wget -q -O - https://api.example.com/users)
echo "$RESPONSE" | jq '.name'
HTTP ステータスコードを取得する
# curl
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://example.com)
echo $HTTP_CODE # → 200
# ステータスコードによる分岐
if [ "$(curl -s -o /dev/null -w "%{http_code}" https://api.example.com/health)" = "200" ]; then
echo "サービス正常"
else
echo "サービス異常"
fi
# wget(終了コードで成功/失敗を判断する方が一般的)
if wget -q --spider https://api.example.com/health; then
echo "URL にアクセス可能"
fi
失敗時にエラーにする
# curl(-f でHTTPエラーを終了コードに反映)
curl -f https://api.example.com/data
echo $? # 200番台以外なら 22
# set -e と組み合わせるとエラー時に即終了
set -e
curl -f -s https://api.example.com/data | jq .
# wget(4xx・5xx で自動的に非ゼロを返す)
wget -q https://api.example.com/data
echo $? # 成功で 0、失敗で非ゼロ
レスポンス時間を計測する
# curl(-w でフォーマット指定)
curl -s -o /dev/null -w "接続: %{time_connect}s\n合計: %{time_total}s\n" \
https://example.com
# 詳細な計測
curl -s -o /dev/null -w "
DNS解決: %{time_namelookup}s
TCP接続: %{time_connect}s
TLS: %{time_appconnect}s
最初のバイト: %{time_starttransfer}s
合計: %{time_total}s
" https://example.com
よく使うオプションの対応表
| 操作 | curl | wget |
|---|---|---|
| 出力を抑制 | -s / --silent | -q / --quiet |
| ファイルに保存 | -o ファイル名 | -O ファイル名 |
| URL名で保存 | -O | (デフォルト) |
| 標準出力に出力 | (デフォルト) | -O - |
| リダイレクトを追う | -L | (デフォルト) |
| POST | -X POST -d データ | --method=POST --body-data=データ |
| ヘッダー送信 | -H "名前: 値" | --header="名前: 値" |
| Basic認証 | -u user:pass | --user=user --password=pass |
| Cookie | -b cookie | --header="Cookie: cookie" |
| タイムアウト | --max-time 秒 | --timeout=秒 |
| リトライ | --retry N | -t N |
| レジューム | -C - | -c |
| SSL無視 | -k | --no-check-certificate |
| プロキシ | -x proxy:port | -e "https_proxy=proxy:port" |
| 詳細表示 | -v | -v |
| ヘッダーのみ | -I | --server-response |
| 再帰取得 | ❌ | -r |
| HTTP コード取得 | -w "%{http_code}" | 終了コードで判断 |
インストール
# Ubuntu/Debian
sudo apt install curl wget
# RHEL/CentOS/Fedora
sudo dnf install curl wget
# macOS(Homebrew)
brew install curl wget
# バージョン確認
curl --version
wget --version
トラブルシューティング
curl で SSL エラーが出る
# エラー例
curl: (60) SSL certificate problem: certificate has expired
# 原因確認
curl -v https://example.com 2>&1 | grep -E "SSL|TLS|certificate"
# CA 証明書を更新
sudo apt update && sudo apt install --reinstall ca-certificates
# 一時的に SSL を無効化(開発時のみ)
curl -k https://example.com
wget でファイル名が index.html になる
# URL がディレクトリを指しているためファイル名が自動設定される
# -O でファイル名を明示指定
wget -O output.html https://example.com
# または Content-Disposition のファイル名を使う
wget --content-disposition https://example.com/download/
curl でレスポンスが文字化けする
# gzip 圧縮レスポンスを自動展開する
curl --compressed https://example.com
# または手動で展開
curl https://example.com | gunzip
よくある質問(FAQ)
Q1. どちらを使えばいいか分からない場合は?
API を叩く・データを送信する作業なら curl、ファイルをダウンロードするだけなら wget を選べば大体うまくいきます。特にこだわりがなければ curl を覚えておく方が応用範囲が広いです。
Q2. macOS にはどちらが入っていますか?
macOS には curl がデフォルトでインストールされています。wget はデフォルトでは入っておらず、Homebrew でインストールする必要があります。
Q3. スクリプトで使うなら curl と wget どちらが向いていますか?
スクリプトなら curl を推奨します。理由は以下の通りです。
# curl が優れている点
# ① HTTP ステータスコードを取得しやすい
STATUS=$(curl -s -o /dev/null -w "%{http_code}" URL)
# ② -f オプションでエラー時に非ゼロを返す
curl -f URL || echo "エラー"
# ③ レスポンスとステータスコードを同時に取得
curl -s -w "\n%{http_code}" URL
Q4. wget -q -O - という書き方はよく見ますが何ですか?
-q は出力を抑制(quiet モード)、-O - は標準出力への出力です。合わせて「エラーメッセージを出さずにレスポンスを標準出力に出す」という意味で、スクリプト内で変数に代入する場合によく使われます。
# wget で curl -s と同等の書き方
RESPONSE=$(wget -q -O - https://api.example.com/data)
Q5. curl と wget 以外に同様のツールはありますか?
httpie(http コマンド):人間に優しい出力・JSON が見やすい
pip install httpie
http GET https://api.example.com/users
aria2:並列ダウンロードが得意・マルチプロトコル対応
sudo apt install aria2
aria2c -x 4 https://example.com/large.zip # 4並列でダウンロード
xh:Rust製の httpie 互換・高速
cargo install xh
まとめ
curl と wget の使い分けをまとめます。
curl を使う場面:
- REST API・GraphQL を叩く
- POST・PUT・DELETE などのリクエストを送る
- ヘッダー・Cookie・認証情報を細かく制御したい
- スクリプトでステータスコードをチェックしたい
- レスポンス時間を計測したい
wget を使う場面:
- ファイルを手軽にダウンロードしたい(コマンドがシンプル)
- 再帰的にサイトをダウンロードしたい
- 自動リトライを簡単に設定したい
- ダウンロードのレジューム(
-c)をシンプルに使いたい
# API を叩くなら curl
curl -s -X POST https://api.example.com/data \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{"key": "value"}' | jq .
# ファイルをダウンロードするなら wget(シンプル)
wget https://example.com/file.zip
# または curl
curl -LO https://example.com/file.zip
参考リンク
公式ドキュメント
関連記事(本サイト)
- Linux grep オプション一覧 – grepコマンドリファレンス
- jq コマンド完全リファレンス – JSON処理(curl との組み合わせに便利)
- 「EADDRINUSE: address already in use」エラーの解決方法 – ポート関連
- nginx: bind() failed の解決方法 – Web サーバー関連
本記事は2026年6月時点の情報をもとに、curl 8.x・wget 1.21.x・Ubuntu 24.04 LTS での動作確認に基づき作成しています。バージョンによってオプションの挙動が異なる場合があるため、最新情報は各公式ドキュメントをご確認ください。
-
前の記事
Rails Solid Cable の使い方|Action Cable をRedisなしで動かす 2026.07.01
-
次の記事
「nginx: [emerg] bind() to 0.0.0.0:80 failed」の原因と解決方法 2026.07.02
コメントを書く