curl

curl 7.88+

curl 빠른 참조: HTTP 메서드, 헤더, 인증, JSON, 폼, 업로드, 다운로드, 리디렉트, 디버깅, 재시도와 연결 제어 — 자주 쓰는 옵션과 실전 예시까지 정리했습니다.

명령어 30개

기본

curl <url>

URL 을 가져와 본문을 stdout 에 출력합니다.

-L 리디렉트 따라가기; -i 헤더 포함; -I HEAD 만; -v verbose; -s silent; -S 에러 표시; --compressed gzip/brotli 디코드

curl -L -s -o website.html https://example.com && curl -sI https://example.com
curl -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.sql

HTTP 메서드 & 헤더

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/reset
curl -H 'Header: value' <url>

사용자 정의 헤더를 한 개 이상 보냅니다(Content-Type, X-API-Key 등).

-H 'X-API-Key: ...'; -H 반복; --json (Content-Type + 페이로드); --form -F (multipart)

curl -s -H 'Authorization: Bearer $TOKEN' -H 'Accept: application/json' https://api.example.com/orders/1
curl -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/article
curl -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/me
curl -H 'Authorization: Bearer <token>'

Bearer 토큰을 보냅니다(--oauth2-bearer 로도 가능).

--oauth2-bearer $TOKEN; --bearer 별칭 (8+)

curl --oauth2-bearer '$GH_TOKEN' -s https://api.github.com/user | jq .login
curl --cert / --key / --cacert

mTLS 용 클라이언트 인증서 / 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 는 기본 폼 인코딩; --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/notes
curl -F 'file=@/path'

multipart/form-data 업로드(브라우저 표준 업로드 포맷)를 보냅니다.

-F field=value; -F file=@path; -F '[email protected];type=image/png'; --form-string raw

curl -s -F 'avatar=@./photo.png' -F 'name=alice' https://api.example.com/profile
curl -G --data-urlencode

URL 인코딩된 쿼리스트링을 만듭니다(값을 자동 URL 인코딩).

-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/search

JSON

curl -d @body.json -H 'Content-Type: application/json'

요청 본문에 JSON 을 담아 보냅니다.

단축 --json (Content-Type + 페이로드를 한 플래그로)

curl -s --json @body.json -X POST https://api.example.com/orders && curl --json '{"a":1}' https://api.example.com/x
curl | 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]}'

쿠키 & 세션

curl -b cookies.txt / -c cookies.txt

쿠키 읽기(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/dashboard
curl --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 (binary)

curl -v --trace-ascii /tmp/login.trace https://api.example.com/login
curl --next

연쇄 요청 사이에 플래그를 리셋("URL parm 0" / 연결 누수 방지).

--next; 호출별 리셋

curl -s -H 'Accept: text/html' https://example.com --next -s -H 'Accept: application/json' https://example.com/api
curl -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.iso
curl --retry N --retry-delay S --retry-all-errors

일시적 오류를 자동 재시도(네트워크, 5xx, reset).

--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.zip
curl --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.iso
curl -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-servers

NIC 에 바인드(VPN 인터페이스 IP 사용) 또는 DNS 를 오버라이드 — split 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.com
curl --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.com
curl --insecure / --cacert

TLS 검증을 건너뛰거나 오버라이드(insecure = 디버그 전용).

-k / --insecure; --cacert ca.pem; --capath dir

curl -k --cacert dev-ca.pem -s https://localhost:8443/health

설정

curl -K config.curl

설정 파일로 curl 을 구동 — 반복 가능한 스크립트에 좋습니다.

--config file; 호출별 옵션

curl -sK - <<'EOF'\nurl = 'https://api.example.com/me'\nheader = 'Authorization: Bearer '$'${TOKEN}'\n
curl --parallel / --parallel-max

단일 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

스크립트에서 흔히 쓰는 URL 가져오기 관용구: silent, follow, HTTP 오류 시 실패, 출력.

-f / --fail; --fail-with-body 오류 시 본문 표시; -s silent; -L follow; -S 에러 표시

curl -fsSL -o installer.sh https://get.docker.com && sh installer.sh
curl --compressed / --no-compressed

--compressed 로 gzip/deflate/brotli 요청 — 대역폭 절약.

--compressed

curl --compressed -s -A 'Mozilla/5.0' https://news.example.com | head -c 200

관련 명령어 치트시트

curl 소개

curl은 URL로 데이터를 전송하는 명령줄 도구로, Daniel Stenberg(bagder)가 1997년에 처음 릴리스했고 현재는 글로벌 커뮤니티가 개발하고 있습니다. 현재 안정 버전은 curl 8.x이며, 거의 모든 운영 체제, 컨테이너 이미지, CI 러너에 동봉되어 있습니다. 25가지 이상의 프로토콜 — HTTP/1.1, HTTP/2, HTTP/3(QUIC), HTTPS, FTP, FTPS, SFTP, SCP, SMTP, IMAP, POP3, LDAP, MQTT, WebSocket, SMB 등 — 을 지원하며, 이를 일관된 CLI와 수백 개의 옵션으로 노출합니다. 일반적인 용도로는 API 빠른 디버깅(`curl -v`), 페이지네이션 루프(`curl -Z` 병렬), 파일 업로드(`-F`, `-T`), 폼 제출, OAuth 플로우, 쿠키 jar(`-c` / `-b`), 리디렉트 추적(`-L`)이 있습니다. 근육 기억이 되어야 할 두 옵션: `-i`는 응답 헤더를 표시하고, `-o /dev/null`은 본문을 침묵시킵니다. 스크립트, CI 작업, 컨테이너에서 엔드포인트를 두드리고 싶지만 무거운 클라이언트를 설치하고 싶지 않을 때 curl을 사용하세요. curl은 명시적으로 요청하지 않은 것은 업로드하지 않습니다. 스크립트의 `-d @file`과 `--upload-file` 페이로드는 커밋 전에 검토하고, 긴 원라이너보다는 `~/.curlrc`에 개인용 기본값을 작성하세요.

치트시트 버전 1.0.0