linux curl命令詳解

來源:互聯網
上載者:User

一、參數詳解

 -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 驗證方法
 --proxy-basic  在代理上使用基本驗證
 --proxy-digest  在代理上使用數字身分識別驗證
 --proxy-ntlm  在代理上使用ntlm身分識別驗證
 -P/--ftp-port <address>  使用連接埠地址,而不是使用PASV
 -Q/--quote <cmd>  檔案傳輸前,發送命令到伺服器
 -r/--range <range>  檢索來自HTTP/1.1或FTP伺服器位元組範圍
 --range-file    讀取(SSL)的隨機檔案
 -R/--remote-time  在本地組建檔案時,保留遠程檔案時間
 --retry <num>  傳輸出現問題時,重試的次數
 --retry-delay <seconds>  傳輸出現問題時,設定稍候再試時間
 --retry-max-time <seconds>  傳輸出現問題時,設定最大重試時間
 -s/--silent  靜音。不輸出任何東西
 -S/--show-error  顯示錯誤
 --socks4 <host[:port]>  用socks4代理給定主機和連接埠
 --socks5 <host[:port]>  用socks5代理給定主機和連接埠
 -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/--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  用進度條顯示當前的傳送狀態

二,常用curl執行個體 

1,抓取頁面內容到一個檔案中
[root@10.10.90.97 ~]# curl -o home.html  http://www.sina.com.cn 
2,用-O(大寫的),後面的url要具體到某個檔案,不然抓不下來。我們還可以用正則來抓取東西 
[root@10.10.90.97 ~]# curl -O http://www.it415.com/czxt/linux/25002_3.html 
3,類比表單資訊,類比登入,儲存cookie資訊 
[root@10.10.90.97 ~]# curl -c ./cookie_c.txt -F log=aaaa -F pwd=****** http://blog.51yip.com/wp-login.php 
4,類比表單資訊,類比登入,儲存頭資訊 
[root@10.10.90.97 ~]# curl -D ./cookie_D.txt -F log=aaaa -F pwd=****** http://blog.51yip.com/wp-login.php 
-c(小寫)產生的cookie和-D裡面的cookie是不一樣的。
5,使用cookie檔案 
[root@10.10.90.97 ~]# curl -b ./cookie_c.txt  http://blog.51yip.com/wp-admin 
6,斷點續傳,-C(大寫的)
[root@10.10.90.97 ~]# curl -C -O http://www.sina.com.cn 
7,傳送資料,最好用登入頁面測試,因為你傳值過去後,curl回抓資料,你可以看到你傳值有沒有成功 
[root@10.10.90.97 ~]# curl -d log=aaaa  http://blog.51yip.com/wp-login.php 
8,顯示抓取錯誤 
[root@10.10.90.97 ~]# curl -f http://www.sina.com.cn/asdf 
curl: (22) The requested URL returned error: 404
[root@10.10.90.97 ~]# curl http://www.sina.com.cn/asdf 
<HTML><HEAD><TITLE>404,not found</TITLE>
。。。。。。。。。。。。
9,偽造來源地址,有的網站會判斷,請求來源地址 
[root@10.10.90.97 ~]# curl -e http://localhost http://www.sina.com.cn 
10,當我們經常用curl去搞人家東西的時候,人家會把你的IP給屏蔽掉的,這個時候,我們可以用代理 
[root@10.10.90.97 ~]# curl -x 10.10.90.83:80 -o home.html http://www.sina.com.cn 
11,比較大的東西,我們可以分段下載
[root@10.10.90.97 ~]# curl -r 0-100 -o img.part1 http://i2.f.itc.cn/thumb/180/bj/6018/b_60178154.jpg 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   101  100   101    0     0   1926      0 --:--:-- --:--:-- --:--:--     0
[root@10.10.90.97 ~]# curl -r 100-200 -o img.part2 http://i2.f.itc.cn/thumb/180/bj/6018/b_60178154.jpg 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   101  100   101    0     0   3498      0 --:--:-- --:--:-- --:--:--   98k
[root@10.10.90.97 ~]# curl -r 200- -o img.part3 http://i2.f.itc.cn/thumb/180/bj/6018/b_60178154.jpg     
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13515  100 13515    0     0   154k      0 --:--:-- --:--:-- --:--:--  280k
[root@10.10.90.97 ~]# ll |grep img.part
-rw-r--r-- 1 root root   101 Jan 24 10:59 img.part1
-rw-r--r-- 1 root root   101 Jan 24 11:00 img.part2
-rw-r--r-- 1 root root 13515 Jan 24 11:00 img.part3
用的時候,把他們cat一下就OK了,cat img.part* >img.jpg
12,不顯示下載進度資訊
[root@10.10.90.97 ~]# curl -s -o aaa.jpg  
13,顯示下載進度條 
[root@10.10.90.97 ~]# curl -# -O  http://www.it415.com/czxt/linux/25002_3.html 
######################################################################## 100.0%
14,通過ftp下載檔案 
[root@10.10.90.97 ~]# curl -u 使用者名稱:密碼 -O http://blog.51yip.com/demo/curtain/bbstudy_files/style.css 
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
101  1934  101  1934    0     0   3184      0 --:--:-- --:--:-- --:--:--  7136
或者用下面的方式
[root@10.10.90.97 ~]# curl -O ftp://xukai:test@192.168.242.144:21/www/focus/enhouse/index.php 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 87518  100 87518    0     0  2312k      0 --:--:-- --:--:-- --:--:-- 11.5M
15,通過ftp上傳 
[root@10.10.90.97 ~]# curl -T xukai.php ftp://xukai:test@192.168.242.144:21/www/focus/enhouse/         
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 87518    0     0  100 87518      0  2040k --:--:-- --:--:-- --:--:-- 8901k

  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.