網路城邦
上一篇 回創作列表 下一篇  字體:
[ubuntu]命令行下載工具Wget
2011/03/17 00:02:59瀏覽2795|回應0|推薦0
下載最新版本 http://www.gnu.org/software/wget/wget.html

使用下列命令編譯安裝:
tar zxvf wget-1.9.tar.gz
cd wget-1.9
./configure
make
sudo make install

用法:
wget [選項] [下載地址]
1.Wget常用參數
◆ -b:背景下載,Wget 預設的是把文件下載到當前目錄。
◆ -O:將文件下載到指定的目錄中。
◆ -P:保存文件之前先創建指定名稱的目錄。
◆ -t:嘗試連接次數,當Wget無法與服務器建立連接時,嘗試連接多少次。
◆ -c:斷點續傳,如果下載中斷,那麼連接恢復時會從上次斷點開始下載。

Wget 也支持HTTP和FTP代理功能:
> 編輯配置文件「/etc/wgetrc」
> 以文字編輯器打開上述文件,將 "http_proxy"和"ftp_proxoy"前的#去掉,然後在這兩項後輸入相應的代理服務器的地址,存檔退出即可。

特殊功能:
Wget可下載整個 網站
例如下載http://man.chinaunix.net整個Man手冊中心。

可輸入 wget -r -p -np -k http://man.chinaunix.net
說明:
-r參數是指使用遞迴下載
-p是指下載所有顯示完整網頁所以需要的文件,如圖片等
-np是指不搜索上層目錄
-k則是指將絕對鏈接轉換為相對鏈接

【檔案說明】wget -help
GNU Wget 1.9,非互動式檔案下載工具。
用法:wget [選項]... [URL]...

長選項必須用的參數在使用短選項時也是必須的。

啟動:
-V, --version 顯示 Wget 版本並離開。
-h, --help 印出此輔助說明。
-b, --background 啟動後進入背景作業。
-e, --execute=指令 執行‘.wgetrc’形式的指令。

Logging and input file:
-o, --output-file=FILE log messages to FILE.
-a, --append-output=FILE append messages to FILE.
-d, --debug print debug output.
-q, --quiet quiet (no output).
-v, --verbose be verbose (this is the default).
-nv, --non-verbose turn off verboseness, without being quiet.
-i, --input-file=FILE download URLs found in FILE.
-F, --force-html treat input file as HTML.
-B, --base=URL prepends URL to relative links in -F -i file.

Download:
-t, --tries=NUMBER set number of retries to NUMBER (0 unlimits).
--retry-connrefused retry even if connection is refused.
-O --output-document=FILE write documents to FILE.
-nc, --no-clobber don't clobber existing files or use .# suffixes.
-c, --continue resume getting a partially-downloaded file.
--progress=TYPE select progress gauge type.
-N, --timestamping don't re-retrieve files unless newer than local.
-S, --server-response print server response.
--spider don't download anything.
-T, --timeout=SECONDS set all timeout values to SECONDS.
--dns-timeout=SECS set the DNS lookup timeout to SECS.
--connect-timeout=SECS set the connect timeout to SECS.
--read-timeout=SECS set the read timeout to SECS.
-w, --wait=SECONDS wait SECONDS between retrievals.
--waitretry=SECONDS wait 1...SECONDS between retries of a retrieval.
--random-wait wait from 0...2*WAIT secs between retrievals.
-Y, --proxy=on/off turn proxy on or off.
-Q, --quota=NUMBER set retrieval quota to NUMBER.
--bind-address=ADDRESS bind to ADDRESS (hostname or IP) on local host.
--limit-rate=RATE limit download rate to RATE.
--dns-cache=off disable caching DNS lookups.
--restrict-file-names=OS restrict chars in file names to ones OS allows.

Directories:
-nd, --no-directories don't create directories.
-x, --force-directories force creation of directories.
-nH, --no-host-directories don't create host directories.
-P, --directory-prefix=PREFIX save files to PREFIX/...
--cut-dirs=NUMBER ignore NUMBER remote directory components.

HTTP options:
--http-user=USER set http user to USER.
--http-passwd=PASS set http password to PASS.
-C, --cache=on/off (dis)allow server-cached data (normally allowed).
-E, --html-extension save all text/html documents with .html extension.
--ignore-length ignore `Content-Length' header field.
--header=STRING insert STRING among the headers.
--proxy-user=USER set USER as proxy username.
--proxy-passwd=PASS set PASS as proxy password.
--referer=URL include `Referer: URL' header in HTTP request.
-s, --save-headers save the HTTP headers to file.
-U, --user-agent=AGENT identify as AGENT instead of Wget/VERSION.
--no-http-keep-alive disable HTTP keep-alive (persistent connections).
--cookies=off don't use cookies.
--load-cookies=FILE load cookies from FILE before session.
--save-cookies=FILE save cookies to FILE after session.
--post-data=STRING use the POST method; send STRING as the data.
--post-file=FILE use the POST method; send contents of FILE.

FTP 選項:
-nr, --dont-remove-listing 不要刪除‘.listing’檔案。
-g, --glob=on/off 設定是否展開有萬用字元的檔名。
--passive-ftp 使用「被動」傳輸模式。
--retr-symlinks 在遞迴模式中,下載連結所指示的檔案(連至目錄
則例外)。

Recursive retrieval:
-r, --recursive recursive download.
-l, --level=NUMBER maximum recursion depth (inf or 0 for infinite).
--delete-after delete files locally after downloading them.
-k, --convert-links convert non-relative links to relative.
-K, --backup-converted before converting file X, back up as X.orig.
-m, --mirror shortcut option equivalent to -r -N -l inf -nr.
-p, --page-requisites get all images, etc. needed to display HTML page.
--strict-comments turn on strict (SGML) handling of HTML comments.

遞迴下載的接受/拒絕選項:
-A, --accept=列表 接受的檔案樣式列表,以逗號分隔。
-R, --reject=列表 排除的檔案樣式列表,以逗號分隔。
-D, --domains=列表 接受的網域列表,以逗號分隔。
--exclude-domains=列表 排除的網域列表,以逗號分隔。
--follow-ftp 跟隨 HTML 文件中的 FTP 連結。
--follow-tags=列表 會跟隨的 HTML 標籤,以逗號分隔。
-G, --ignore-tags=列表 會忽略的 HTML 標籤,以逗號分隔。
-H, --span-hosts 遞迴時可進入其它主機。
-L, --relative 只跟隨相對連結。
-I, --include-directories=列表 下載的目錄列表。
-X, --exclude-directories=列表 排除的目錄列表。
-np, --no-parent 不搜尋上層的目錄。

請將錯誤報告或建議寄給

參考資料:
http://blog.xuite.net/jackie.xie/bluelove/6059542
( 興趣嗜好電腦3C )
回應 推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=dietitian&aid=4987666