wget
网络
用法
wget [options] <url>把网址下载成文件,并且会自己跟随跳转;这正是它和 curl 的区别,curl 不特意指定就打印到终端,而 macOS 默认不带 wget。
常用选项
| 选项 | 含义 |
|---|---|
| -O <file> | Choose the output name; -O - writes to stdout like curl does. |
| -c | Continue a partly downloaded file instead of starting over. |
| -q | Quiet. Pair with -O - to pipe the body somewhere. |
| -P <dir> | Put downloads into a directory. |
| -r -np -k | Recursive mirror, never climb above the start URL, rewrite links for local reading. |
| --limit-rate=1m | Cap the bandwidth so the download does not saturate the line. |
| -N | Only fetch if the remote file is newer than the local copy. |
示例
wget -c https://example.com/big.isoResume 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 | headBehave 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