curl 是 CommandLine Uniform Resource Locator (命令行統一資源定位器) 的簡寫,基於開源庫 libcurl 。
curl 相比 wget 功能更底層,可在命令行 (或腳本) 中按 URL 分塊傳輸數據。 可用於汽車 電視機 路由器 打印機 音頻設備 手機 平闆電腦 機頂盒 媒體播放器中。
支持特性: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets
支持協議: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
另請參閱: wget dante-server
curl -I www.baidu.com curl -s -o /dev/null www.baidu.com
遠程文件
curl -O http://xxx.edu.cn/test-full.tar.gz
分塊下載
curl -r 0-10000 -o local_part1.tar.gz http://xxx.edu.cn/test-full.tar.gz curl -r 10001- -o local_part2.tar.gz http://xxx.edu.cn/test-full.tar.gz cat local_part* > local_test.tar.gz
基本語法
curl [options...] <url>
| 參數 | EN 解釋 | 中文翻譯 | 備注 |
|---|---|---|---|
| --anyauth | Pick "any" authentication method (H) | 選擇任何身份驗證方法 (H) | |
| -a, --append | Append to target file when uploading (F/SFTP) | 上傳時追加到目標文件 (F/SFTP) | |
| --basic | Use HTTP Basic Authentication (H) | 使用 HTTP 基本身份驗證 (H) | |
| --cacert FILE | CA certificate to verify peer against (SSL) | CA 證書驗證對等方 (SSL) | |
| --capath DIR | CA directory to verify peer against (SSL) | CA 目錄驗證對等方 (SSL) | |
| -E, --cert CERT[:PASSWD] | Client certificate file and password (SSL) | 客戶端證書文件 口令 (SSL) | |
| --cert-status | Verify the status of the server certificate (SSL) | 驗證服務器證書狀態 (SSL) | |
| --cert-type TYPE | Certificate file type (DER/PEM/ENG) (SSL) | 證書文件類型 (DER/PEM/ENG) (SSL) | |
| --ciphers LIST | SSL ciphers to use (SSL) | 要使用的 SSL 暗號 | |
| --compressed | Request compressed response (using deflate or gzip) | 請求壓縮響應 (使用 deflate 或 gzip ) | |
| -K, --config FILE | Read config from FILE | 從 FILE 讀取配置 | |
| --connect-timeout SECONDS | Maximum time allowed for connection | 允許的最大連接時間 | |
| -C, --continue-at OFFSET | Resumed transfer OFFSET | 恢復傳輸 OFFSET | |
| -b, --cookie STRING/FILE | Read cookies from STRING/FILE (H) | 從 STRING/FILE 中讀取 Cookie (H) | |
| -c, --cookie-jar FILE | Write cookies to FILE after operation (H) | 操作後將 Cookie 寫入 FILE (H) | |
| --create-dirs | Create necessary local directory hierarchy | 創建必要的本地目錄層次結構 | |
| --crlf | Convert LF to CRLF in upload | 在上傳時將 LF 轉換為 CRLF | |
| --crlfile FILE | Get a CRL list in PEM format from the given file | 從給定文件獲取 PEM 格式 CRL 列錶 | |
| -d, --data DATA | HTTP POST data (H) | HTTP POST 數據 (H) | |
| --data-raw DATA | HTTP POST data, '@' allowed (H) | HTTP POST 數據,允許 '@' (H) | |
| --data-ascii DATA | HTTP POST ASCII data (H) | HTTP POST ASCII 數據 (H) | |
| --data-binary DATA | HTTP POST binary data (H) | HTTP POST 二進製數據 (H) | |
| --data-urlencode DATA | HTTP POST data url encoded (H) | HTTP POST 數據編碼 url (H) | |
| --delegation STRING | GSS-API delegation permission | GSS-API 委托權限 | |
| --digest | Use HTTP Digest Authentication (H) | 使用 HTTP 摘要驗證 (H) | |
| --disable-eprt | Inhibit using EPRT or LPRT (F) | 阻止使用 EPRT 或 LPRT (F) | |
| --disable-epsv | Inhibit using EPSV (F) | 阻止使用 EPSV (F) | |
| --dns-servers | DNS server addrs to use: 1.1.1.1;2.2.2.2 | 要使用的 DNS 服務器地址:1.1.1.1; 2.2.2.2 | |
| --dns-interface | Interface to use for DNS requests | DNS 請求使用接口 | |
| --dns-ipv4-addr | IPv4 address to use for DNS requests, dot notation | DNS 請求使用 IPv4 地址,點錶示法 | |
| --dns-ipv6-addr | IPv6 address to use for DNS requests, dot notation | DNS 請求使用 IPv6 地址,點錶示法 | |
| -D, --dump-header FILE | Write the headers to FILE | 把頭寫入 FILE | |
| --egd-file FILE | EGD socket path for random data (SSL) | 隨機數據的 EGD 套接字路徑 (SSL) | |
| --engine ENGINE | Crypto engine (use "--engine list" for list) (SSL) | 加密引擎 (使用 "--engine list" 為列錶) (SSL) | |
| --expect100-timeout SECONDS | How long to wait for 100-continue (H) | 100 次繼續等待時間 (H) | |
| -f, --fail | Fail silently (no output at all) on HTTP errors (H) | 齣現 HTTP 錯誤時默默失敗 (根本沒有輸齣) (H) | |
| --false-start | Enable TLS False Start | 啓用 TLS False 啓動 | |
| -F, --form CONTENT | Specify HTTP multipart POST data (H) | 指定 HTTP 分段 POST 數據 (H) | |
| --form-string STRING | Specify HTTP multipart POST data (H) | 指定 HTTP 分段 POST 數據 data (H) | |
| --ftp-account DATA | Account data string (F) | 帳戶數據字符串 (F) | |
| --ftp-alternative-to-user COMMAND | String to replace "USER [name]" (F) | 要替換 "USER [name]" 的字符串 (F) | |
| --ftp-create-dirs | Create the remote dirs if not present (F) | 創建遠程目錄,若不存在 (F) | |
| --ftp-method [MULTICWD/NOCWD/SINGLECWD] | Control CWD usage (F) | 控製 CWD 用法 (F) | |
| --ftp-pasv | Use PASV/EPSV instead of PORT (F) | 使用 PASV/EPSV,而不是 PORT (F) | |
| -P, --ftp-port ADR | Use PORT with given address instead of PASV (F) | 使用給定地址 PORT,而不是 PASV (F) | |
| --ftp-skip-pasv-ip | Skip the IP address for PASV (F) | 跳過 PASV IP 地址 (F) | |
| --ftp-pret | Send PRET before PASV (for drftpd) (F) | 在 PASV 之前發送 PRET (對於 drftpd) (F) | |
| --ftp-ssl-ccc | Send CCC after authenticating (F) | 驗證後發送 CCC (F) | |
| --ftp-ssl-ccc-mode ACTIVE/PASSIVE | Set CCC mode (F) | 設置 CCC 模式 (F) | |
| --ftp-ssl-control | Require SSL/TLS for FTP login, clear for transfer (F) | FTP 登錄需要 SSL/TLS,傳輸歸零 (F) | |
| -G, --get | Send the -d data with a HTTP GET (H) | 以 HTTP GET 發送 -d 數據 (H) | |
| -g, --globoff | Disable URL sequences and ranges using {} and [] | 以 {} [] 禁用 URL 序列 範圍 | |
| -H, --header LINE | Pass custom header LINE to server (H) | 把自定義頭 LINE 傳遞給服務器 (H) | |
| -I, --head | Show document info only | 僅展示文檔信息 | |
| -h, --help | This help text | 顯示幫助文本信息 | |
| --hostpubmd5 MD5 | Hex-encoded MD5 string of the host public key. (SSH) | 十六進製編碼主機公鑰 MD5 字符串 (SSH) | |
| -0, --http1.0 | Use HTTP 1.0 (H) | 使用 HTTP 1.0 (H) | |
| --http1.1 | Use HTTP 1.1 (H) | 使用 HTTP 1.1 (H) | |
| --http2 | Use HTTP 2 (H) | 使用 HTTP 2 (H) | |
| --ignore-content-length | Ignore the HTTP Content-Length header | 忽略 HTTP Content-Length 頭 | |
| -i, --include | Include protocol headers in the output (H/F) | 在輸齣中包括協議頭 (H/F) | |
| -k, --insecure | Allow connections to SSL sites without certs (H) | 允許無證書連接到 SSL 站點 (H) | |
| --interface INTERFACE | Use network INTERFACE (or address) | 使用網絡 INTERFACE (或地址) | |
| -4, --ipv4 | Resolve name to IPv4 address | 將名稱解析成 IPv4 地址 | |
| -6, --ipv6 | Resolve name to IPv6 address | 將名稱解析成 IPv6 地址 | |
| -j, --junk-session-cookies | Ignore session cookies read from file (H) | 忽略從文件讀取的會話 cookie (H) | |
| --keepalive-time SECONDS | Wait SECONDS between keepalive probes | 在 Keepalive 探針之間等待 SECONDS | |
| --key KEY | Private key file name (SSL/SSH) | 私鑰文件名 (SSL/SSH) | |
| --key-type TYPE | Private key file type (DER/PEM/ENG) (SSL) | 私鑰文件類型 (DER/PEM/ENG) (SSL) | |
| --krb LEVEL | Enable Kerberos with security LEVEL (F) | 以安全級彆 LEVEL 啓用 Kerberos (F) | |
| --libcurl FILE | Dump libcurl equivalent code of this command line | 轉儲本命令行的 libcurl 等效代碼 | |
| --limit-rate RATE | Limit transfer speed to RATE | 把傳輸速度限製為 RATE | |
| -l, --list-only | List only mode (F/POP3) | 僅列齣模式 (F/POP3) | |
| --local-port RANGE | Force use of RANGE for local port numbers | 把 RANGE 強製用於本地端口號 | |
| L, --location | Follow redirects (H) | 跟隨重定嚮 | |
| --location-trusted | Like '--location', and send auth to other hosts (H) | 類似 '--location',並將 auth 發送給其他主機 (H) | |
| --login-options OPTIONS | Server login options (IMAP, POP3, SMTP) | 服務器登錄選項 (IMAP, POP3, SMTP) | |
| -M, --manual | Display the full manual | 顯示完整手冊 | |
| --mail-from FROM | Mail from this address (SMTP) | 郵件來自此地址 (SMTP) | |
| --mail-rcpt TO | Mail to this/these addresses (SMTP) | 郵到 此/這些 地址 (SMTP) | |
| --mail-auth AUTH | Originator address of the original email (SMTP) | 原電子郵件的發起人地址 (SMTP) | |
| --max-filesize BYTES | Maximum file size to download (H/F) | 要下載的最大文件尺寸 (H/F) | |
| --max-redirs NUM | Maximum number of redirects allowed (H) | 最大允許重定嚮次數 (H) | |
| -m, --max-time SECONDS | Maximum time allowed for the transfer | 允許傳輸的最大時間 | |
| --metalink | Process given URLs as metalink XML file | 將給定 URL 處理成 metalink XML 文件 | |
| --negotiate | Use HTTP Negotiate (SPNEGO) authentication (H) | 使用 HTTP 協商 (SPNEGO) 身份驗證 (H) | |
| -n, --netrc | Must read .netrc for user name and password | 為用戶名 口令必須讀取 .netrc | |
| --netrc-optional | Use either .netrc or URL; overrides -n | 使用 .netrc 或 URL;覆蓋 -n | |
| --netrc-file FILE | Specify FILE for netrc | 為 netrc 指定 FILE | |
| -:, --next | Allows the following URL to use a separate set of options | 允許之後 URL 使用單獨選項集 | |
| --no-alpn | Disable the ALPN TLS extension (H) | 禁用 ALPN TLS 擴展 (H) | |
| -N, --no-buffer | Disable buffering of the output stream | 禁用輸齣流緩衝 | |
| --no-keepalive | Disable keepalive use on the connection | 禁止 keepalive 用於連接 | |
| --no-npn | Disable the NPN TLS extension (H) | 禁用 NPN TLS 擴展 (H) | |
| --no-sessionid | Disable SSL session-ID reusing (SSL) | 禁止重用 SSL 會話 ID (SSL) | |
| --noproxy | List of hosts which do not use proxy | 列齣不使用代理的主機 | |
| --ntlm | Use HTTP NTLM authentication (H) | 使用 HTTP NTLM 身份驗證 (H) | |
| --oauth2-bearer TOKEN | OAuth 2 Bearer Token (IMAP, POP3, SMTP) | OAuth 2 不記名令牌 (IMAP, POP3, SMTP) | |
| -o, --output FILE | Write to FILE instead of stdout | 寫入 FILE 文件,而不是標準輸齣 | |
| --pass PASS | Pass phrase for the private key (SSL/SSH) | 傳遞私鑰短語 (SSL/SSH) | |
| --path-as-is | Do not squash .. sequences in URL path | 不要壓縮 .. 序列 URL 路徑 | |
| --pinnedpubkey FILE/HASHES | Public key to verify peer against (SSL) | 用來驗證對等方的公鑰 (SSL) | |
| --post301 | Do not switch to GET after following a 301 redirect (H) | 在隨 301 重定嚮後,不切換到 GET (H) | |
| --post302 | Do not switch to GET after following a 302 redirect (H) | 在隨 302 重定嚮後,不切換到 GET (H) | |
| --post303 | Do not switch to GET after following a 303 redirect (H) | 在隨 303 重定嚮後,不切換到 GET (H) | |
| -#, --progress-bar | Display transfer progress as a progress bar | 以進度條方式顯示傳輸進度 | |
| --proto PROTOCOLS | Enable/disable PROTOCOLS | 啓用/禁用 PROTOCOLS 協議 | |
| --proto-default PROTOCOL | Use PROTOCOL for any URL missing a scheme | 對任何缺少方案的 URL 使用 PROTOCOL 協議 | |
| --proto-redir PROTOCOLS | Enable/disable PROTOCOLS on redirect | 啓用/禁用 重定嚮 PROTOCOLS 協議 | |
| -x, --proxy [PROTOCOL://]HOST[:PORT] | Use proxy on given port | 在給定端口上使用代理 | |
| --proxy-anyauth | Pick "any" proxy authentication method (H) | 選擇任何代理身份驗證方法 (H) | |
| --proxy-basic | Use Basic authentication on the proxy (H) | 在代理上使用基本身份驗證 (H) | |
| --proxy-digest | Use Digest authentication on the proxy (H) | 在代理上使用摘要身份驗證 (H) | |
| --proxy-negotiate | Use HTTP Negotiate (SPNEGO) authentication on the proxy (H) | 在代理上使用 HTTP 協商 (SPNEGO) 身份驗證 (H) | |
| --proxy-ntlm | Use NTLM authentication on the proxy (H) | 在代理上使用 NTLM 身份驗證 (H) | |
| --proxy-service-name NAME | SPNEGO proxy service name | SPNEGO 代理服務名稱 | |
| --service-name NAME | SPNEGO service name | SPNEGO 服務名稱 | |
| -U, --proxy-user USER[:PASSWORD] | Proxy user and password | 代理用戶 口令 | |
| --proxy1.0 HOST[:PORT] | Use HTTP/1.0 proxy on given port | 在給定端口上使用 HTTP/1.0 代理 | |
| -p, --proxytunnel | Operate through a HTTP proxy tunnel (using CONNECT) | 通過 HTTP 代理隧道進行操作 (使用 CONNECT) | |
| --pubkey KEY | Public key file name (SSH) | 公鑰文件名 (SSH) | |
| -Q, --quote CMD | Send command(s) to server before transfer (F/SFTP) | 傳輸前將命令發送給服務器 (F/SFTP) | |
| --random-file FILE | File for reading random data from (SSL) | 用於從中讀取隨機數據的文件 (SSL) | |
| -r, --range RANGE | Retrieve only the bytes within RANGE | 僅檢索 RANGE 範圍內的字節 | |
| --raw | Do HTTP "raw"; no transfer decoding (H) | 做 HTTP "raw";不解碼傳輸 (H) | |
| -e, --referer | Referer URL (H) | 引薦 URL (H) | |
| -J, --remote-header-name | Use the header-provided filename (H) | 使用頭提供文件名 (H) | |
| -O, --remote-name | Write output to a file named as the remote file | 將輸齣寫入到名為遠程文件的文件 | |
| --remote-name-all | Use the remote file name for all URLs | 對所有 URL 使用遠程文件名 | |
| -R, --remote-time | Set the remote file's time on the local output | 在本地輸齣設置遠程文件時間 | |
| -X, --request COMMAND | Specify request command to use | 指定要使用的請求命令 | |
| --resolve HOST:PORT:ADDRESS | Force resolve of HOST:PORT to ADDRESS | 把 HOST:PORT 強製解析為 ADDRESS | |
| --retry NUM | Retry request NUM times if transient problems occur | 重試請求次 NUM 數,若齣現暫時性問題 | |
| --retry-delay SECONDS | Wait SECONDS between retries | 重試之間等待 SECONDS 秒 | |
| --retry-max-time SECONDS | Retry only within this period | 僅在此區間重試 | |
| --sasl-ir | Enable initial response in SASL authentication | 在 SASL 身份驗證中啓用初始響應 | |
| -S, --show-error |
Show error With -s, make curl show errors when they occur |
展示錯誤 采用 -s,使 curl 發生錯誤時展示錯誤 |
|
| -s, --silent | Silent mode (don't output anything) | 靜音模式 (不輸齣任何內容) | |
| --socks4 HOST[:PORT] | SOCKS4 proxy on given host + port | 給定主機 + 端口上的 SOCKS4 代理 | |
| --socks4a HOST[:PORT] | SOCKS4a proxy on given host + port | 給定主機 + 端口上的 SOCKS4a 代理 | |
| --socks5 HOST[:PORT] | SOCKS5 proxy on given host + port | 給定主機 + 端口上的 SOCKS5 代理 | |
| --socks5-hostname HOST[:PORT] | SOCKS5 proxy, pass host name to proxy | SOCKS5 代理,把主機名傳遞給代理 | |
| --socks5-gssapi-service NAME | SOCKS5 proxy service name for GSS-API | GSS-API 的 SOCKS5 代理服務名 | |
| --socks5-gssapi-nec | Compatibility with NEC SOCKS5 server | 兼容 NEC SOCKS5 服務器 | |
| -Y, --speed-limit RATE | Stop transfers below RATE for 'speed-time' secs | 當在 RATE 每 'speed-time' 秒內時停止傳輸 | |
| -y, --speed-time SECONDS | Trigger 'speed-limit' abort after SECONDS (default: 30) | 在 SECONDS 秒後觸發 '限速' 中止 (默認:30) | |
| --ssl | Try SSL/TLS (FTP, IMAP, POP3, SMTP) | 嘗試 SSL/TLS (FTP, IMAP, POP3, SMTP) | |
| --ssl-reqd | Require SSL/TLS (FTP, IMAP, POP3, SMTP) | 要求 SSL/TLS (FTP, IMAP, POP3, SMTP) | |
| -2, --sslv2 | Use SSLv2 (SSL) | 使用 SSLv2 (SSL) | |
| -3, --sslv3 | Use SSLv3 (SSL) | 使用 SSLv3 (SSL) | |
| --ssl-allow-beast | Allow security flaw to improve interop (SSL) | 允許安全缺陷,以改善互操作 (SSL) | |
| --ssl-no-revoke | Disable cert revocation checks (WinSSL) | 禁用證書吊銷檢查 (WinSSL) | |
| --stderr FILE | Where to redirect stderr (use "-" for stdout) | 重定嚮標準錯誤位置 (使用 "-" 為標準輸齣) | |
| --tcp-nodelay | Use the TCP_NODELAY option | 使用 TCP_NODELAY 選項 | |
| -t, --telnet-option OPT=VAL | Set telnet option | 設置 telnet 選項 | |
| --tftp-blksize VALUE | Set TFTP BLKSIZE option (must be >512) | 設置 TFTP BLKSIZE 選項 (必須 > 512) | |
| -z, --time-cond TIME | Transfer based on a time condition | 傳輸基於時間條件 | |
| -1, --tlsv1 | Use >= TLSv1 (SSL) | 使用 >= TLSv1 (SSL) | |
| --tlsv1.0 | Use TLSv1.0 (SSL) | 使用 TLSv1.0 (SSL) | |
| --tlsv1.1 | Use TLSv1.1 (SSL) | 使用 TLSv1.1 (SSL) | |
| --tlsv1.2 | Use TLSv1.2 (SSL) | 使用 TLSv1.2 (SSL) | |
| --trace FILE | Write a debug trace to FILE | 將調試跟蹤寫入 FILE | |
| --trace-ascii FILE | Like --trace, but without hex output | 類似 --trace,但沒有十六進製輸齣 | |
| --trace-time | Add time stamps to trace/verbose output | 將時間戳添加到 跟蹤/詳細 輸齣 | |
| --tr-encoding | Request compressed transfer encoding (H) | 請求壓縮傳輸編碼 (H) | |
| -T, --upload-file FILE | Transfer FILE to destination | 把 FILE 文件傳輸到目的地 | |
| --url URL | URL to work with | 處理 URL | |
| -B, --use-ascii | Use ASCII/text transfer | 使用 ASCII/text 傳輸 | |
| -u, --user USER[:PASSWORD] | Server user and password | 服務器用戶 口令 | |
| --tlsuser USER | TLS username | TLS 用戶名 | |
| --tlspassword STRING | TLS password | TLS 口令 | |
| --tlsauthtype STRING | TLS authentication type (default: SRP) | TLS 身份驗證類型 (默認: SRP) | |
| --unix-socket FILE | Connect through this Unix domain socket | 通過此 Unix 域套接字連接 | |
| -A, --user-agent STRING | Send User-Agent STRING to server (H) | 把用戶代理 STRING 發送給服務器 (H) | |
| -v, --verbose | Make the operation more talkative | 使操作更健談 | |
| -V, --version | Show version number and quit | 展示版本號並離開 | |
| -w, --write-out FORMAT | Use output FORMAT after completion | 完成後使用輸齣 FORMAT 格式 | |
| --xattr | Store metadata in extended file attributes | 把元數據存儲在擴展文件屬性中 | |
| -q | Disable .curlrc (must be first parameter) | 禁用 .curlrc (必須是第一參數) |
-I, --head 展示響應頭信息。
-m, --max-time SECONDS 最大訪問超時時間。
譬如: curl -I -m 5 -s -w "%{http_code}\n" -o /dev/null www.baidu.com
curl -I -m 5 -s -w "%{http_code}\n" -o /dev/null www.baidu.com | egrep "30[12]|200" | wc -l
| 功能 | 命令 | 文字解釋 | 示例 | 示例解釋 |
|---|---|---|---|---|
| 版本 | curl -V | 展示版本信息 | ||
| curl --version | ||||
| 手冊 | curl -M | 展示完整手冊 | ||
| curl --manual | ||||
| 幫助 | curl -h | 展示幫助信息 | ||
| curl --help |
版權聲明: 本文為獨傢原創稿件,版權歸 樂數軟件 ,未經許可不得轉載。