Linux工具之curl與wget高階使用
1、curl(檔案傳輸工具)
常用引數如下:
-c,--cookie-jar:將cookie寫入到檔案
-b,--cookie:從檔案中讀取cookie
-C,--continue-at:斷點續傳
-d,--data:http post方式傳送資料
-D,--dump-header:把header資訊寫入到檔案
-F,--from:模擬http表達提交資料
-s,--slient:減少輸出資訊
-o,--output:將資訊輸出到檔案
-O,--remote-name:按照伺服器上的檔名,存在本地
--l,--head:僅返回頭部資訊
-u,--user[user:pass]:設定http認證使用者和密碼
-T,--upload-file:上傳檔案
-e,--referer:指定引用地址
-x,--proxy:指定代理伺服器地址和埠
-w,--write-out:輸出指定格式內容
--retry:重試次數
--connect-timeout:指定嘗試連線的最大時間/s
使用示例:
例1:抓取頁面到指定檔案,如果有亂碼可以使用iconv轉碼
# curl -o baidu.html www.baidu.com
# curl –s –o baidu.html www.baidu.com |iconv -f utf-8 #減少輸出資訊
例2:模擬瀏覽器頭(user-agent)
# curl -A "Mozilla/4.0 (compatible;MSIE 6.0; Windows NT 5.0)" www.baidu.com
例3:處理重定向頁面
# curl –L http://192.168.1.100/301.php #預設curl是不處理重定向
例4:模擬使用者登陸,儲存cookie資訊到cookies.txt檔案,再使用cookie登陸
# curl -c ./cookies.txt -F NAME=user -F PWD=***URL #NAME和PWD是表單屬性不同,每個網站基本都不同
# curl -b ./cookies.txt –o URL
例5:獲取HTTP響應頭headers
# curl -I http://www.baidu.com
# curl -D ./header.txt http://www.baidu.com #將headers儲存到檔案中
例6:訪問HTTP認證頁面
# curl –u user:pass URL
例7:通過ftp上傳和下載檔案
# curl -T filename ftp://user:pass@ip/docs #上傳
# curl -O ftp://user:pass@ip/filename #下載
部落格:http://lizhenliang.blog.51cto.com
2、wget(檔案下載工具)
常用引數如下:
2.1 啟動引數
-V,--version:顯示版本號
-h,--help:檢視幫助
-b,--background:啟動後轉入後臺執行
2.2 日誌記錄和輸入檔案引數
-o,--output-file=file:把記錄寫到file檔案中
-a,--append-output=file:把記錄追加到file檔案中
-i,--input-file=file:從file讀取url來下載
2.3 下載引數
-bind-address=address:指定本地使用地址
-t,-tries=number:設定最大嘗試連線次數
-c,-continue:接著下載沒有下載完的檔案
-O,-output-document=file:將下載內容寫入到file檔案中
-spider:不下載檔案
-T,-timeout=sec:設定響應超時時間
-w,-wait=sec:兩次嘗試之間間隔時間
--limit-rate=rate:限制下載速率
-progress=type:設定進度條
2.4 目錄引數
-P,-directory-prefix=prefix:將檔案儲存到指定目錄
2.5 HTTP引數
-http-user=user:設定http使用者名稱
-http-passwd=pass:設定http密碼
-U,--user-agent=agent:偽裝代理
-no-http-keep-alive:關閉http活動連結,變成永久連結
-cookies=off:不使用cookies
-load-cookies=file:在開始會話前從file檔案載入cookies
-save-cookies=file:在會話結束將cookies儲存到file檔案
2.6 FTP引數
-passive-ftp:預設值,使用被動模式
-active-ftp:使用主動模式
2.7 遞迴下載排除引數
-A,--accept=list:分號分割被下載副檔名的列表
-R,--reject=list:分號分割不被下載副檔名的列表
-D,--domains=list:分號分割被下載域的列表
--exclude-domains=list:分號分割不被下載域的列表
使用示例:
例1:下載單個檔案到當前目錄下,也可以-P指定下載目錄
# wgethttp://nginx.org/download/nginx-1.8.0.tar.gz
例2:對於網路不穩定的使用者可以使用-c和--tries引數,保證下載完成
# wget --tries=20 -c http://nginx.org/download/nginx-1.8.0.tar.gz
例3:下載大的檔案時,我們可以放到後臺去下載,這時會生成wget-log檔案來儲存下載進度
# wget -b http://nginx.org/download/nginx-1.8.0.tar.gz
例4:可以利用—spider引數判斷網址是否有效
# wget --spider http://nginx.org/download/nginx-1.8.0.tar.gz
例5:自動從多個連結下載檔案
# cat url_list.txt #先建立一個URL檔案
http://nginx.org/download/nginx-1.8.0.tar.gz
http://nginx.org/download/nginx-1.6.3.tar.gz
# wget -i url_list.txt
例6:限制下載速度
# wget --limit-rate=1m http://nginx.org/download/nginx-1.8.0.tar.gz
例7:登陸ftp下載檔案
# wget --ftp-user=user --ftp-password=pass ftp://ip/filename
本文轉自Jacken_yang 51CTO部落格,原文連結:http://blog.51cto.com/linuxnote/1652126,如需轉載請自行聯絡原作者
相關文章
- curl與wget高階用法wget
- curl wget命令常用wget
- CUUG ORACLE高階工具的使用Oracle
- linux高階工具命令 -- vmstat介紹Linux
- Git原理與高階使用(1)Git
- Git原理與高階使用(2)Git
- Git原理與高階使用(3)Git
- Git原理與高階使用(4)Git
- Linux基礎命令---wget下載工具Linuxwget
- Docker: docker pull, wget, curl, git clone 等如何更快?DockerwgetGit
- 從基礎到高階,帶你深入瞭解和使用curl命令(二)
- curl 安裝與使用
- elasticsearch 搜尋引擎工具的高階使用Elasticsearch
- linux高階工具命令(三)使用gprof和oprofile查詢效能瓶頸Linux
- SpringBoot高階篇MongoDB之基本環境搭建與使用Spring BootMongoDB
- Linux高階流量控制tc使用Linux
- WGET——LINUX下WEB檔案提取工具(轉)wgetLinuxWeb
- linux的wget命令使用說明Linuxwget
- Kotlin——高階篇(二):高階函式詳解與標準的高階函式使用Kotlin函式
- AWK高階之內部函式使用函式
- 分享Linux Grep高階使用者指南Linux
- Mac 下 iTerm2 命令工具翻筋斗雲加速 wget、curl、Git、brew、Composer、yarn、NPM 等命令MacwgetGitYarnNPM
- Pytest高階進階之Fixture
- 分享:玩Linux筆記(2) —— 神奇的curl工具Linux筆記
- 《前端之路》之 JavaScript 高階技巧、高階函式(一)前端JavaScript函式
- kubernetes高階之叢集中使用sysctlsTLS
- Jenkins 使用指南 之 高階應用篇Jenkins
- 高階BOM工具智慧打包功能
- Linux中wget用法Linuxwget
- Linux wget詳解Linuxwget
- HTTPie:替代 Curl 和 Wget 的現代 HTTP 命令列客戶端HTTPwget命令列客戶端
- Java高階-執行緒同步lock與unlock使用Java執行緒
- 超級強悍的下載之工具curl(轉)
- 面試之 Redis 基礎、高階特性與效能調優面試Redis
- RabbitMQ高階之訊息限流與延時佇列MQ佇列
- JavaScript 高階系列之節流 [throttle] 與防抖 [debounce]JavaScript
- Nginx的高階使用Nginx
- ModelSerializer 高階使用