linuxcurl命令參數(shù)有哪些及怎么使用

本文小編為大家詳細介紹“l(fā)inux curl命令參數(shù)有哪些及怎么使用”,內(nèi)容詳細,步驟清晰,細節(jié)處理妥當,希望這篇“l(fā)inux curl命令參數(shù)有哪些及怎么使用”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。

站在用戶的角度思考問題,與客戶深入溝通,找到太白網(wǎng)站設計與太白網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設計與互聯(lián)網(wǎng)技術結合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站制作、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、國際域名空間、網(wǎng)絡空間、企業(yè)郵箱。業(yè)務覆蓋太白地區(qū)。

linux curl是一個利用url規(guī)則在命令行下工作的文件傳輸工具。它支持文件的上傳和下載,所以是綜合傳輸工具,但按傳統(tǒng),習慣稱url為下載工具。

一,curl命令參數(shù)

-a/--append 上傳文件時,附加到目標文件

-a/--user-agent <string>  設置用戶代理發(fā)送給服務器

- anyauth   可以使用“任何”身份驗證方法

-b/--cookie <name=string/file> cookie字符串或文件讀取位置

- basic 使用http基本驗證

-b/--use-ascii 使用ascii /文本傳輸

-c/--cookie-jar <file> 操作結束后把cookie寫入到這個文件中

-c/--continue-at <offset>  斷點續(xù)轉(zhuǎn)

-d/--data <data>   http post方式傳送數(shù)據(jù)

--data-ascii <data>  以ascii的方式post數(shù)據(jù)

--data-binary <data> 以二進制的方式post數(shù)據(jù)

--negotiate     使用http身份驗證

--digest        使用數(shù)字身份驗證

--disable-eprt  禁止使用eprt或lprt

--disable-epsv  禁止使用epsv

-d/--dump-header <file> 把header信息寫入到該文件中

--egd-file <file> 為隨機數(shù)據(jù)(ssl)設置egd socket路徑

--tcp-nodelay   使用tcp_nodelay選項

-e/--referer 來源網(wǎng)址

-e/--cert <cert[:passwd]> 客戶端證書文件和密碼 (ssl)

--cert-type <type> 證書文件類型 (der/pem/eng) (ssl)

--key <key>     私鑰文件名 (ssl)

--key-type <type> 私鑰文件類型 (der/pem/eng) (ssl)

--pass  <pass>  私鑰密碼 (ssl)

--engine <eng>  加密引擎使用 (ssl). "--engine list" for list

--cacert <file> ca證書 (ssl)

--capath <directory> ca目錄 (made using c_rehash) to verify peer against (ssl)

--ciphers <list>  ssl密碼

--compressed    要求返回是壓縮的形勢 (using deflate or gzip)

--connect-timeout <seconds> 設置最大請求時間

--create-dirs   建立本地目錄的目錄層次結構

--crlf          上傳是把lf轉(zhuǎn)變成crlf

-f/--fail          連接失敗時不顯示http錯誤

--ftp-create-dirs 如果遠程目錄不存在,創(chuàng)建遠程目錄

--ftp-method [multicwd/nocwd/singlecwd] 控制cwd的使用

--ftp-pasv      使用 pasv/epsv 代替端口

--ftp-skip-pasv-ip 使用pasv的時候,忽略該ip地址

--ftp-ssl       嘗試用 ssl/tls 來進行ftp數(shù)據(jù)傳輸

--ftp-ssl-reqd  要求用 ssl/tls 來進行ftp數(shù)據(jù)傳輸

-f/--form <name=content> 模擬http表單提交數(shù)據(jù)

-form-string <name=string> 模擬http表單提交數(shù)據(jù)

-g/--globoff 禁用網(wǎng)址序列和范圍使用{}和[]

-g/--get 以get的方式來發(fā)送數(shù)據(jù)

-h/--help 幫助

-h/--header <line>自定義頭信息傳遞給服務器

--ignore-content-length  忽略的http頭信息的長度

-i/--include 輸出時包括protocol頭信息

-i/--head  只顯示文檔信息

從文件中讀取-j/--junk-session-cookies忽略會話cookie

- 界面<interface>指定網(wǎng)絡接口/地址使用

- krb4 <級別>啟用與指定的安全級別krb4

-j/--junk-session-cookies 讀取文件進忽略session cookie

--interface <interface> 使用指定網(wǎng)絡接口/地址

--krb4 <level>  使用指定安全級別的krb4

-k/--insecure 允許不使用證書到ssl站點

-k/--config  指定的配置文件讀取

-l/--list-only 列出ftp目錄下的文件名稱

--limit-rate <rate> 設置傳輸速度

--local-port<num> 強制使用本地端口號

-m/--max-time <seconds> 設置最大傳輸時間

--max-redirs <num> 設置最大讀取的目錄數(shù)

--max-filesize <bytes> 設置最大下載的文件總量

-m/--manual  顯示全手動

-n/--netrc 從netrc文件中讀取用戶名和密碼

--netrc-optional 使用 .netrc 或者 url來覆蓋-n

--ntlm          使用 http ntlm 身份驗證

-n/--no-buffer 禁用緩沖輸出

-o/--output 把輸出寫到該文件中

-o/--remote-name 把輸出寫到該文件中,保留遠程文件的文件名

-p/--proxytunnel   使用http代理

--proxy-anyauth 選擇任一代理身份驗證方法

--proxy-basic   在代理上使用基本身份驗證

--proxy-digest  在代理上使用數(shù)字身份驗證

--proxy-ntlm    在代理上使用ntlm身份驗證

-p/--ftp-port <address> 使用端口地址,而不是使用pasv

-q/--quote <cmd>文件傳輸前,發(fā)送命令到服務器

-r/--range <range>檢索來自http/1.1或ftp服務器字節(jié)范圍

--range-file 讀?。╯sl)的隨機文件

-r/--remote-time   在本地生成文件時,保留遠程文件時間

--retry <num>   傳輸出現(xiàn)問題時,重試的次數(shù)

--retry-delay <seconds>  傳輸出現(xiàn)問題時,設置重試間隔時間

--retry-max-time <seconds> 傳輸出現(xiàn)問題時,設置最大重試時間

-s/--silent靜音模式。不輸出任何東西

-s/--show-error   顯示錯誤

--socks4 <host[:port]> 用socks4代理給定主機和端口

--socks5 <host[:port]> 用socks5代理給定主機和端口

--stderr <file>
-t/--telnet-option <opt=val> telnet選項設置

--trace <file>  對指定文件進行debug

--trace-ascii <file> like --跟蹤但沒有hex輸出

--trace-time    跟蹤/詳細輸出時,添加時間戳

-t/--upload-file <file> 上傳文件

--url <url>     spet url to work with

-u/--user <user[:password]>設置服務器的用戶和密碼

-u/--proxy-user <user[:password]>設置代理用戶名和密碼

-v/--verbose

-v/--version 顯示版本信息

-w/--write-out [format]什么輸出完成后

-x/--proxy <host[:port]>在給定的端口上使用http代理

-x/--request <command>指定什么命令

-y/--speed-time 放棄限速所要的時間。默認為30

-y/--speed-limit 停止傳輸速度的限制,速度時間'秒

-z/--time-cond  傳送時間設置

-0/--http1.0  使用http 1.0

-1/--tlsv1  使用tlsv1(ssl)

-2/--sslv2 使用sslv2的(ssl)

-3/--sslv3         使用的sslv3(ssl)

--3p-quote      like -q for the source url for 3rd party transfer

--3p-url        使用url,進行第三方傳送

--3p-user       使用用戶名和密碼,進行第三方傳送

-4/--ipv4   使用ip4

-6/--ipv6   使用ip6

-#/--progress-bar 用進度條顯示當前的傳送狀態(tài)

-a/--append 上傳文件時,附加到目標文件

-a/--user-agent <string>  設置用戶代理發(fā)送給服務器

- anyauth   可以使用“任何”身份驗證方法

-b/--cookie <name=string/file> cookie字符串或文件讀取位置

- basic 使用http基本驗證

-b/--use-ascii 使用ascii /文本傳輸

-c/--cookie-jar <file> 操作結束后把cookie寫入到這個文件中

-c/--continue-at <offset>  斷點續(xù)轉(zhuǎn)

-d/--data <data>   http post方式傳送數(shù)據(jù)

--data-ascii <data>  以ascii的方式post數(shù)據(jù)

--data-binary <data> 以二進制的方式post數(shù)據(jù)

--negotiate     使用http身份驗證

--digest        使用數(shù)字身份驗證

--disable-eprt  禁止使用eprt或lprt

--disable-epsv  禁止使用epsv

-d/--dump-header <file> 把header信息寫入到該文件中

--egd-file <file> 為隨機數(shù)據(jù)(ssl)設置egd socket路徑

--tcp-nodelay   使用tcp_nodelay選項

-e/--referer 來源網(wǎng)址

-e/--cert <cert[:passwd]> 客戶端證書文件和密碼 (ssl)

--cert-type <type> 證書文件類型 (der/pem/eng) (ssl)

--key <key>     私鑰文件名 (ssl)

--key-type <type> 私鑰文件類型 (der/pem/eng) (ssl)

--pass  <pass>  私鑰密碼 (ssl)

--engine <eng>  加密引擎使用 (ssl). "--engine list" for list

--cacert <file> ca證書 (ssl)

--capath <directory> ca目錄 (made using c_rehash) to verify peer against (ssl)

--ciphers <list>  ssl密碼

--compressed    要求返回是壓縮的形勢 (using deflate or gzip)

--connect-timeout <seconds> 設置最大請求時間

--create-dirs   建立本地目錄的目錄層次結構

--crlf          上傳是把lf轉(zhuǎn)變成crlf

-f/--fail          連接失敗時不顯示http錯誤

--ftp-create-dirs 如果遠程目錄不存在,創(chuàng)建遠程目錄

--ftp-method [multicwd/nocwd/singlecwd] 控制cwd的使用

--ftp-pasv      使用 pasv/epsv 代替端口

--ftp-skip-pasv-ip 使用pasv的時候,忽略該ip地址

--ftp-ssl       嘗試用 ssl/tls 來進行ftp數(shù)據(jù)傳輸

--ftp-ssl-reqd  要求用 ssl/tls 來進行ftp數(shù)據(jù)傳輸

-f/--form <name=content> 模擬http表單提交數(shù)據(jù)

-form-string <name=string> 模擬http表單提交數(shù)據(jù)

-g/--globoff 禁用網(wǎng)址序列和范圍使用{}和[]

-g/--get 以get的方式來發(fā)送數(shù)據(jù)

-h/--help 幫助

-h/--header <line>自定義頭信息傳遞給服務器

--ignore-content-length  忽略的http頭信息的長度

-i/--include 輸出時包括protocol頭信息

-i/--head  只顯示文檔信息

從文件中讀取-j/--junk-session-cookies忽略會話cookie

- 界面<interface>指定網(wǎng)絡接口/地址使用

- krb4 <級別>啟用與指定的安全級別krb4

-j/--junk-session-cookies 讀取文件進忽略session cookie

--interface <interface> 使用指定網(wǎng)絡接口/地址

--krb4 <level>  使用指定安全級別的krb4

-k/--insecure 允許不使用證書到ssl站點

-k/--config  指定的配置文件讀取

-l/--list-only 列出ftp目錄下的文件名稱

--limit-rate <rate> 設置傳輸速度

--local-port<num> 強制使用本地端口號

-m/--max-time <seconds> 設置最大傳輸時間

--max-redirs <num> 設置最大讀取的目錄數(shù)

--max-filesize <bytes> 設置最大下載的文件總量
-m/--manual  顯示全手動

-n/--netrc 從netrc文件中讀取用戶名和密碼

--netrc-optional 使用 .netrc 或者 url來覆蓋-n

--ntlm          使用 http ntlm 身份驗證

-n/--no-buffer 禁用緩沖輸出

-o/--output 把輸出寫到該文件中

-o/--remote-name 把輸出寫到該文件中,保留遠程文件的文件名

-p/--proxytunnel   使用http代理

--proxy-anyauth 選擇任一代理身份驗證方法

--proxy-basic   在代理上使用基本身份驗證

--proxy-digest  在代理上使用數(shù)字身份驗證

--proxy-ntlm    在代理上使用ntlm身份驗證

-p/--ftp-port <address> 使用端口地址,而不是使用pasv

-q/--quote <cmd>文件傳輸前,發(fā)送命令到服務器

-r/--range <range>檢索來自http/1.1或ftp服務器字節(jié)范圍

--range-file 讀?。╯sl)的隨機文件

-r/--remote-time   在本地生成文件時,保留遠程文件時間

--retry <num>   傳輸出現(xiàn)問題時,重試的次數(shù)

--retry-delay <seconds>  傳輸出現(xiàn)問題時,設置重試間隔時間

--retry-max-time <seconds> 傳輸出現(xiàn)問題時,設置最大重試時間

-s/--silent靜音模式。不輸出任何東西

-s/--show-error   顯示錯誤

--socks4 <host[:port]> 用socks4代理給定主機和端口

--socks5 <host[:port]> 用socks5代理給定主機和端口

--stderr <file>

-t/--telnet-option <opt=val> telnet選項設置

--trace <file>  對指定文件進行debug

--trace-ascii <file> like --跟蹤但沒有hex輸出

--trace-time    跟蹤/詳細輸出時,添加時間戳

-t/--upload-file <file> 上傳文件

--url <url>     spet url to work with

-u/--user <user[:password]>設置服務器的用戶和密碼

-u/--proxy-user <user[:password]>設置代理用戶名和密碼

-v/--verbose

-v/--version 顯示版本信息

-w/--write-out [format]什么輸出完成后

-x/--proxy <host[:port]>在給定的端口上使用http代理

-x/--request <command>指定什么命令

-y/--speed-time 放棄限速所要的時間。默認為30

-y/--speed-limit 停止傳輸速度的限制,速度時間'秒

-z/--time-cond  傳送時間設置

-0/--http1.0  使用http 1.0

-1/--tlsv1  使用tlsv1(ssl)

-2/--sslv2 使用sslv2的(ssl)

-3/--sslv3         使用的sslv3(ssl)

--3p-quote      like -q for the source url for 3rd party transfer

--3p-url        使用url,進行第三方傳送

--3p-user       使用用戶名和密碼,進行第三方傳送

-4/--ipv4   使用ip4

-6/--ipv6   使用ip6

-#/--progress-bar 用進度條顯示當前的傳送狀態(tài)

二,常用curl實例

1,抓取頁面內(nèi)容到一個文件中

[root@krlcgcms01 mytest]# curl -o home.html 

[root@krlcgcms01 mytest]# curl -o home.html 

2,用-o(大寫的),后面的url要具體到某個文件,不然抓不下來。我們還可以用正則來抓取東西

[root@krlcgcms01 mytest]# curl -o

[root@krlcgcms01 mytest]# curl -o

3,模擬表單信息,模擬登錄,保存cookie信息

[root@krlcgcms01 mytest]# curl -c ./cookie_c.txt -f log=aaaa -f pwd=******

[root@krlcgcms01 mytest]# curl -c ./cookie_c.txt -f log=aaaa -f pwd=******

4,模擬表單信息,模擬登錄,保存頭信息

[root@krlcgcms01 mytest]# curl -d ./cookie_d.txt -f log=aaaa -f pwd=******

[root@krlcgcms01 mytest]# curl -d ./cookie_d.txt -f log=aaaa -f pwd=******

-c(小寫)產(chǎn)生的cookie和-d里面的cookie是不一樣的。

5,使用cookie文件

[root@krlcgcms01 mytest]# curl -b ./cookie_c.txt 

[root@krlcgcms01 mytest]# curl -b ./cookie_c.txt 

6,斷點續(xù)傳,-c(大寫的)

[root@krlcgcms01 mytest]# curl -c -o

7,傳送數(shù)據(jù),最好用登錄頁面測試,因為你傳值過去后,curl回抓數(shù)據(jù),你可以看到你傳值有沒有成功

[root@krlcgcms01 mytest]# curl -d log=aaaa 

[root@krlcgcms01 mytest]# curl -d log=aaaa 

8,顯示抓取錯誤,下面這個例子,很清楚的表明了。

[root@krlcgcms01 mytest]# curl -f

curl: (22) the requested url returned error: 404

[root@krlcgcms01 mytest]# curl

<html><head><title>404,not found</title>

。。。。。。。。。。。。

[root@krlcgcms01 mytest]# curl -f

curl: (22) the requested url returned error: 404

[root@krlcgcms01 mytest]# curl

<html><head><title>404,not found</title>

。。。。。。。。。。。。

9,偽造來源地址,有的網(wǎng)站會判斷,請求來源地址。

[root@krlcgcms01 mytest]# curl -e

[root@krlcgcms01 mytest]# curl -e

10,當我們經(jīng)常用curl去搞人家東西的時候,人家會把你的ip給屏蔽掉的,這個時候,我們可以用代理

[root@krlcgcms01 mytest]# curl -x 24.10.28.84:32779 -o home.html

[root@krlcgcms01 mytest]# curl -x 24.10.28.84:32779 -o home.html
11,比較大的東西,我們可以分段下載

[root@krlcgcms01 mytest]# curl -r 0-100 -o img.part1 -

content/uploads/2010/09/compare_varnish.jpg

% total    % received % xferd  average speed   time    time     time  current

dload  upload   total   spent    left  speed

100   101  100   101    0     0    105      0 --:--:-- --:--:-- --:--:--     0

[root@krlcgcms01 mytest]# curl -r 100-200 -o img.part2 -

content/uploads/2010/09/compare_varnish.jpg

% total    % received % xferd  average speed   time    time     time  current

dload  upload   total   spent    left  speed

100   101  100   101    0     0     57      0  0:00:01  0:00:01 --:--:--     0

[root@krlcgcms01 mytest]# curl -r 200- -o img.part3 -

content/uploads/2010/09/compare_varnish.jpg

% total    % received % xferd  average speed   time    time     time  current

dload  upload   total   spent    left  speed

100  104k  100  104k    0     0  52793      0  0:00:02  0:00:02 --:--:-- 88961

[root@krlcgcms01 mytest]# ls |grep part | xargs du -sh

4.0k    one.part1

112k    three.part3

4.0k    two.part2

[root@krlcgcms01 mytest]# curl -r 0-100 -o img.part1 -

content/uploads/2010/09/compare_varnish.jpg

% total    % received % xferd  average speed   time    time     time  current

dload  upload   total   spent    left  speed

100   101  100   101    0     0    105      0 --:--:-- --:--:-- --:--:--     0

[root@krlcgcms01 mytest]# curl -r 100-200 -o img.part2 -

content/uploads/2010/09/compare_varnish.jpg

% total    % received % xferd  average speed   time    time     time  current

dload  upload   total   spent    left  speed

100   101  100   101    0     0     57      0  0:00:01  0:00:01 --:--:--     0

[root@krlcgcms01 mytest]# curl -r 200- -o img.part3 -

content/uploads/2010/09/compare_varnish.jpg

% total    % received % xferd  average speed   time    time     time  current

dload  upload   total   spent    left  speed

100  104k  100  104k    0     0  52793      0  0:00:02  0:00:02 --:--:-- 88961

[root@krlcgcms01 mytest]# ls |grep part | xargs du -sh

4.0k    one.part1

112k    three.part3

4.0k    two.part2

用的時候,把他們cat一下就ok了,cat img.part* >img.jpg

12,不會顯示下載進度信息

[root@krlcgcms01 mytest]# curl -s -o aaa.jpg

13,顯示下載進度條

[root@krlcgcms01 mytest]# curl -# -o

######################################################################## 100.0%

14,通過ftp下載文件

[zhangy@blackghost ~]$ curl -u 用戶名:密碼 -o

% total    % received % xferd  average speed   time    time     time  current

dload  upload   total   spent    left  speed

101  1934  101  1934    0     0   3184      0 --:--:-- --:--:-- --:--:--  7136

[zhangy@blackghost ~]$ curl -u 用戶名:密碼 -o

% total    % received % xferd  average speed   time    time     time  current

dload  upload   total   spent    left  speed

101  1934  101  1934    0     0   3184      0 --:--:-- --:--:-- --:--:--  7136

或者用下面的方式

[zhangy@blackghost ~]$ curl -o ftp://用戶名:密碼@ip:port/demo/curtain/bbstudy_files/style.css

[zhangy@blackghost ~]$ curl -o ftp://用戶名:密碼@ip:port/demo/curtain/bbstudy_files/style.css

15,通過ftp上傳

[zhangy@blackghost ~]$ curl -t test.sql ftp://用戶名:密碼@ip:port/demo/curtain/bbstudy_files/

[zhangy@blackghost ~]$ curl -t test.sql ftp://用戶名:密碼@ip:port/demo/curtain/bbstudy_files/

讀到這里,這篇“l(fā)inux curl命令參數(shù)有哪些及怎么使用”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內(nèi)容的文章,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

分享題目:linuxcurl命令參數(shù)有哪些及怎么使用
URL標題:http://muchs.cn/article44/ihijhe.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供電子商務、云服務器、網(wǎng)站策劃、網(wǎng)站排名、虛擬主機、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化