本文介紹的是Linux中curl命令和wget命令,這兩者都是用來下載文件的工具,下面來看看詳細的介紹:
一、wget
wget是linux最常用的下載命令, 一般的使用方法是: wget + 空格 + 要下載文件的url路徑
例1:
1
|
wget http: //www .minjieren.com /wordpress-3 .1-zh_CN.zip |
下載文件保存到當前目錄,文件名默認是url最后一個/后面的內容,這里就是 wordpress-3.1-zh_CN.zip
例2:
1
|
wget -O myfile http: //www .minjieren.com /wordpress-3 .1-zh_CN.zip |
通過-O參數,可以指定文件名,這里指定的是myfile
例3:
1
|
wget www.baidu.com |
會在當前目錄生成一個index.html文件
二、curl
在Linux中curl是一個利用URL規則在命令行下工作的文件傳輸工具,可以說是一款很強大的http命令行工具。它支持文件的上傳和下載,是綜合傳輸工具,但按傳統,習慣稱url為下載工具。
語法:# curl [option] [url]
常見參數:
- -A/--user-agent <string> 設置用戶代理發送給服務器
- -b/--cookie <name=string/file> cookie字符串或文件讀取位置
- -c/--cookie-jar <file> 操作結束后把cookie寫入到這個文件中
- -C/--continue-at <offset> 斷點續轉
- -D/--dump-header <file> 把header信息寫入到該文件中
- -e/--referer 來源網址
- -f/--fail 連接失敗時不顯示http錯誤
- -o/--output 把輸出寫到該文件中
- -O/--remote-name 把輸出寫到該文件中,保留遠程文件的文件名
- -r/--range <range> 檢索來自HTTP/1.1或FTP服務器字節范圍
- -s/--silent 靜音模式。不輸出任何東西
- -T/--upload-file <file> 上傳文件
- -u/--user <user[:password]> 設置服務器的用戶和密碼
- -w/--write-out [format] 什么輸出完成后
- -x/--proxy <host[:port]> 在給定的端口上使用HTTP代理
- -#/--progress-bar 進度條顯示當前的傳送狀態
例:
1
|
curl -O http: //download .oracle.com /otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-i586 . tar .gz |
下載文件保存到當前目錄,文件名默認是url最后一個/后面的內容,這里就是 jdk-8u91-linux-i586.tar.gz。
注意:必須要加-O參數,否則是直接在控制臺上顯示文件內容了.
說明:這兩個命令工具,linux系統中缺省不一定有的,如果沒有,需要自己安裝。如果是在ubuntu下。
可以執行如下命令進行安裝
1
|
sudo apt-get install curl |
它們的區別有如下幾點:
1.curl是libcurl這個庫支持的,wget是一個純粹的命令行命令。
2.curl支持更多的協議。curl supports FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS, FILE, POP3, IMAP, SMTP and RTSP at the time of this writing. Wget supports HTTP, HTTPS and FTP.
3.curl 默認支持HTTP1.1(也支持1.0),而wget僅僅支持HTTP1.0規范。引用wget的man page中的一段話吧,
1
|
Please be aware that Wget needs to know the size of the POST data in advance. It's not quite clear how to work around this limitation inherent in HTTP/1.0. Although HTTP/1.1 introduces chunked transfer that doesn't require knowing the request length in advance, a client can't use chunked unless it knows it's talking to an HTTP/1.1 server. And it can't know that until it receives a response, which in turn requires the request to have been completed -- a chicken-and-egg problem. |
4.curl在指定要下載的鏈接時能夠支持URL的序列或集合,而wget則不能這樣;
5.wget支持遞歸下載,而curl則沒有這個功能。(這是wget的一個主要好處,wget也是有優勢的,呵呵)
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對服務器之家的支持。
原文鏈接:http://www.cnblogs.com/51kata/p/5528930.html