linux curl 命令詳解

來源:互聯網
上載者:User

標籤:linux

linux curl是一個利用URL規則在命令列下工作的檔案傳輸工具。它支援檔案的上傳和下載,所以是綜合傳輸工具,但按傳統,習慣稱url為下載工具。


1,抓取頁面內容到一個檔案中


[[email protected] mytest]# curl -o home.html  http://blog.51yip.com  


[[email protected] mytest]# curl -o home.html  http://blog.51yip.com2,用-O(大寫的),後面的url要具體到某個檔案,不然抓不下來。我們還可以用正則來抓取東西


[[email protected] mytest]# curl -O http://blog.51yip.com/wp-content/uploads/2010/09/compare_varnish.jpg   

[[email protected] mytest]# curl -O http://blog.51yip.com/wp-content/uploads/2010/[0-9][0-9]/aaaaa.jpg  


[[email protected] mytest]# curl -O http://blog.51yip.com/wp-content/uploads/2010/09/compare_varnish.jpg

[[email protected] mytest]# curl -O http://blog.51yip.com/wp-content/uploads/2010/[0-9][0-9]/aaaaa.jpg3,類比表單資訊,類比登入,儲存cookie資訊


[[email protected] mytest]# curl -c ./cookie_c.txt -F log=aaaa -F pwd=****** http://blog.51yip.com/wp-login.php  


[[email protected] mytest]# curl -c ./cookie_c.txt -F log=aaaa -F pwd=****** http://blog.51yip.com/wp-login.php4,類比表單資訊,類比登入,儲存頭資訊


[[email protected] mytest]# curl -D ./cookie_D.txt -F log=aaaa -F pwd=****** http://blog.51yip.com/wp-login.php  


[[email protected] mytest]# curl -D ./cookie_D.txt -F log=aaaa -F pwd=****** http://blog.51yip.com/wp-login.php-c(小寫)產生的cookie和-D裡面的cookie是不一樣的。


5,使用cookie檔案


[[email protected] mytest]# curl -b ./cookie_c.txt  http://blog.51yip.com/wp-admin  


[[email protected] mytest]# curl -b ./cookie_c.txt  http://blog.51yip.com/wp-admin6,斷點續傳,-C(大寫的)


[[email protected] mytest]# curl -C -O http://blog.51yip.com/wp-content/uploads/2010/09/compare_varnish.jpg  


[[email protected] mytest]# curl -C -O http://blog.51yip.com/wp-content/uploads/2010/09/compare_varnish.jpg7,傳送資料,最好用登入頁面測試,因為你傳值過去後,curl回抓資料,你可以看到你傳值有沒有成功


[[email protected] mytest]# curl -d log=aaaa  http://blog.51yip.com/wp-login.php  


[[email protected] mytest]# curl -d log=aaaa  http://blog.51yip.com/wp-login.php8,顯示抓取錯誤,下面這個例子,很清楚的表明了。


[[email protected] mytest]# curl -f http://blog.51yip.com/asdf   

curl: (22) The requested URL returned error: 404   

[[email protected] mytest]# curl http://blog.51yip.com/asdf   

  

<HTML><HEAD><TITLE>404,not found</TITLE>   

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


[[email protected] mytest]# curl -f http://blog.51yip.com/asdf

curl: (22) The requested URL returned error: 404

[[email protected] mytest]# curl http://blog.51yip.com/asdf


<HTML><HEAD><TITLE>404,not found</TITLE>

。。。。。。。。。。。。9,偽造來源地址,有的網站會判斷,請求來源地址。


[[email protected] mytest]# curl -e http://localhost http://blog.51yip.com/wp-login.php  


[[email protected] mytest]# curl -e http://localhost http://blog.51yip.com/wp-login.php10,當我們經常用curl去搞人家東西的時候,人家會把你的IP給屏蔽掉的,這個時候,我們可以用代理


[[email protected] mytest]# curl -x 24.10.28.84:32779 -o home.html http://blog.51yip.com  


[[email protected] mytest]# curl -x 24.10.28.84:32779 -o home.html http://blog.51yip.com11,比較大的東西,我們可以分段下載


[[email protected] mytest]# curl -r 0-100 -o img.part1 http://blog.51yip.com/wp-   

  

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   

[[email protected] mytest]# curl -r 100-200 -o img.part2 http://blog.51yip.com/wp-   

  

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   

[[email protected] mytest]# curl -r 200- -o img.part3 http://blog.51yip.com/wp-   

  

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   

[[email protected] mytest]# ls |grep part | xargs du -sh   

4.0K    one.part1   

112K    three.part3   

4.0K    two.part2  


[[email protected] mytest]# curl -r 0-100 -o img.part1 http://blog.51yip.com/wp-


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

[[email protected] mytest]# curl -r 100-200 -o img.part2 http://blog.51yip.com/wp-


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

[[email protected] mytest]# curl -r 200- -o img.part3 http://blog.51yip.com/wp-


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

[[email protected] 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,不會顯示下載進度資訊


[[email protected] mytest]# curl -s -o aaa.jpg  http://blog.51yip.com/wp-content/uploads/2010/09/compare_varnish.jpg  


[[email protected] mytest]# curl -s -o aaa.jpg  http://blog.51yip.com/wp-content/uploads/2010/09/compare_varnish.jpg13,顯示下載進度條


[[email protected] mytest]# curl -# -O  http://blog.51yip.com/wp-content/uploads/2010/09/compare_varnish.jpg   

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


[[email protected] mytest]# curl -# -O  http://blog.51yip.com/wp-content/uploads/2010/09/compare_varnish.jpg

######################################################################## 100.0%14,通過ftp下載檔案


[[email protected] ~]$ 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  


[[email protected] ~]$ 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

或者用下面的方式 查看複製列印?

[[email protected] ~]$ curl -O ftp://使用者名稱:密碼@ip:port/demo/curtain/bbstudy_files/style.css  


[[email protected] ~]$ curl -O ftp://使用者名稱:密碼@ip:port/demo/curtain/bbstudy_files/style.css

15,通過ftp上傳


[[email protected] ~]$ curl -T test.sql ftp://使用者名稱:密碼@ip:port/demo/curtain/bbstudy_files/  


[[email protected] ~]$ curl -T test.sql ftp://使用者名稱:密碼@ip:port/demo/curtain/bbstudy_files/

3


本文出自 “營運之家(Q群:1991706)” 部落格,請務必保留此出處http://304076020.blog.51cto.com/7503470/1550158

linux curl 命令詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.