wget下载文件

Wget

The non-interactive network downloader.
非交互网络下载器。
wget [option]... [URL]... 
Wget is non-interactive, meaning that it can work in the background, while the user is not logged on.
wget是非交互性的,这意味着它可以在后台工作,而用户则不登录。  
This allows you to start a retrieval and disconnect from the system, letting Wget finish the work.  
这可以让你开始检索和断开与系统,让Wget完成工作。
By contrast, most of the Web browsers require constant user's presence, which can be a great hindrance when transferring a lot of data.
相比之下,大多数网页浏览器都需要用户的不断出现,这在传输大量数据时可能是一个很大的障碍。

Wget can follow links in HTML, XHTML, and CSS pages, to create local versions of remote web sites, fully recreating the directory structure of the original site.  
wget可以遵循html、xhtml和css页面中的链接,创建远程网站的本地版本,完全重新创建原始网站的目录结构。
This is sometimes referred to as "recursive downloading."
这有时被称为“递归下载”。
While doing that, Wget respects the Robot Exclusion Standard (/robots.txt).  
在这样做的同时,Wget尊重机器人排除标准(/robots.txt)。
Wget can be instructed to convert the links in downloaded files to point at the local files, for offline viewing.
wget可以被指示将下载文件中的链接转换为指向本地文件,以便离线查看。

Wget has been designed for robustness over slow or unstable network connections; 
Wget已经被设计为对慢或不稳定的网络连接的鲁棒性;
if a download fails due to a network problem, it will keep retrying until the whole file has been retrieved.  
如果由于网络问题下载失败,它将继续重试,直到检索到整个文件。
If the server supports regetting,it will instruct the server to continue the download from where it left off.
如果服务器支持重置,它将指示服务器继续从其中断的地方下载。

Wget does not support Client Revocation Lists (CRLs) so the HTTPS certificate you are connecting to might be revoked by the siteowner.
Wget不支持客户端撤销列表(crl),因此您连接到的https证书可能被站点所有者撤销。

下载文件到当前目录

wget http://uploads.oh100.com/allimg/1709/117-1FZ5102542-52.jpg
在下载的过程中会显示进度条,包含(下载完成百分比,已经下载的字节,当前下载速度,剩余下载时间)。

下载并以不同的文件名保存-O

wget -O wordpress.zip http://www.linuxde.net/download.aspx?id=1080
wget默认会以最后一个符合/的后面的字符来命令,对于动态链接的下载通常文件名会不正确。
错误:下面的例子会下载一个文件并以名称download.aspx?id=1080保存:
wget http://www.linuxde.net/download?id=1
即使下载的文件是zip格式,它仍然以download.php?id=1080命令。
正确:为了解决这个问题,我们可以使用参数-O来指定一个文件名:
wget -O wordpress.zip http://www.linuxde.net/download.aspx?id=1080

wget限速下载–limit-rate=300k

wget --limit-rate=300k http://uploads.oh100.com/allimg/1709/117-1FZ5102542-52.jpg
当你执行wget的时候,它默认会占用全部可能的宽带下载。但是当你准备下载一个大文件,而你还需要下载其它文件时就有必要限速了。

使用wget断点续传-c

wget -c http://www.linuxde.net/testfile.zip
使用wget -c  重新启动下载中断的文件,对于我们下载大文件时突然由于网络等原因中断非常有帮助,我们可以继续接着下载而不是重新下载一个文件。需要继续中断的下载时可以使用-c参数。

使用wget后台下载-b

ubuntu@ip-172-31-3-107:~$ wget --limit-rate=300k -O ps.zip -b  http://uploads.oh100.com/allimg/1709/117-1FZ5102542-52.jpg
Continuing in background, pid 12684.
Output will be written to ‘wget-log’.
对于下载非常大的文件的时候,我们可以使用参数-b进行后台下载,你可以使用以下命令来察看下载进度:
tail -f wget-log

测试下载链接

当你打算进行定时下载,你应该在预定时间测试下载链接是否有效。我们可以增加--spider参数进行检查。
wget --spider URL
wget --spider http://uploads.oh100.com/allimg/1709/117-1FZ5102542-52.jpg

增加重试次数

wget --tries=40 URL
如果网络有问题或下载一个大文件也有可能失败。wget默认重试20次连接下载文件。如果需要,你可以使用--tries增加重试次数。

下载多个文件

wget -i filelist.txt
首先,保存一份下载链接文件:
cat > filelist.txt
url1
url2
url3
url4
接着使用这个文件和参数-i下载。

把下载信息存入日志文件

wget -o download.log URL
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值