wget 是 Linux 系统中用于命令行下载文件的工具,支持 HTTP、HTTPS 和 FTP 协议。wget 具备递归下载、断点续传、后台下载等功能,在网络不稳定或带宽有限的环境中表现出色,能够自动重试失败的下载任务。
| 参数 | 说明 |
|---|
-V | 显示版本信息 |
-h | 显示帮助信息 |
-b | 后台运行 |
-i 文件 | 从文件读取 URL 列表进行批量下载 |
| 参数 | 说明 |
|---|
-O 文件名 | 指定输出文件名 |
-c | 断点续传 |
-t 次数 | 设置重试次数(-t 0 表示无限重试) |
-T 秒 | 设置超时时间 |
-w 秒 | 设置重试等待时间 |
--limit-rate=速率 | 限制下载速度 |
--user-agent=字符串 | 自定义 User-Agent |
| 参数 | 说明 |
|---|
-P 目录 | 指定文件保存目录 |
-nd | 不创建目录结构 |
-x | 强制创建目录结构 |
-nH | 不创建主机名前缀的目录 |
| 参数 | 说明 |
|---|
-r | 启用递归下载 |
-l 深度 | 设置递归深度 |
-np | 不进入父目录 |
-A 后缀 | 仅接受指定后缀的文件 |
-R 后缀 | 拒绝指定后缀的文件 |
-D 域名 | 限制下载的域名列表 |
$ wget http://example.com/file.zip
$ wget -c http://example.com/largefile.zip
$ wget -b http://example.com/largefile.zip
$ wget -O output.zip http://example.com/file.zip
$ wget -P /opt/downloads/ http://example.com/file.zip
将多个 URL 写入文件,每行一个:
$ cat download.txt
http://example.com/file1.zip
http://example.com/file2.zip
http://example.com/file3.zip
$ wget -i download.txt
$ wget -b -c -i download.txt
$ wget --limit-rate=300k http://example.com/largefile.zip
$ wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" \
http://example.com/
$ wget -r -l 2 -np http://example.com/
$ wget -r -l 1 -A.pdf http://example.com/
$ wget -e "http_proxy=http://proxy:8080" http://example.com/file.zip
$ wget --header="Cookie: session=abc123" http://example.com/
$ wget --user=username --password=password http://example.com/protected.zip
$ wget -m -k -p http://example.com/
man wget — 查看完整帮助文档curl — 另一种 HTTP 请求工具