首頁·終端機命令

wget

網路

用法

wget [options] <url>

把網址下載成檔案,並且會自己跟隨轉址;這正是它和 curl 的區別,curl 不特意指定就印到終端機,而 macOS 預設不帶 wget。

常用選項

選項含義
-O <file>Choose the output name; -O - writes to stdout like curl does.
-cContinue a partly downloaded file instead of starting over.
-qQuiet. Pair with -O - to pipe the body somewhere.
-P <dir>Put downloads into a directory.
-r -np -kRecursive mirror, never climb above the start URL, rewrite links for local reading.
--limit-rate=1mCap the bandwidth so the download does not saturate the line.
-NOnly fetch if the remote file is newer than the local copy.

範例

wget -c https://example.com/big.iso

Resume a large download after the connection dropped.

wget -r -np -k https://example.com/docs/

Mirror a documentation tree for offline reading.

wget -qO- https://example.com | head

Behave like curl and print to the terminal.

連不上的時候,這些能把範圍縮小——是名稱解析不了、沒有路由,還是連接埠被擋。

怎麼看

  • 方括號 [ ] 表示這部分可以不寫。
  • 省略號 … 表示可以寫多個。
  • 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。

常見問題

Q. wget 是做什麼的?

把網址下載成檔案,並且會自己跟隨轉址;這正是它和 curl 的區別,curl 不特意指定就印到終端機,而 macOS 預設不帶 wget。

Q. 怎麼寫?

wget [options] <url> —— 方括號表示可以省略的部分。

Q. 值得記的選項有幾個?

這裡列了 7 個,完整列表在 man wget。這條命令屬於網路。

相關命令

man 手冊: man wget