wget命令是对互联网资源进行下载,最近想弄个自助下载并自动上传备份的脚本,由于wget命令不太了解,今天来充充电。
比如运行wget ,你会发现
–2017-04-05 06:18:11– http://xihajun.com/
Resolving xihajun.com (xihajun.com)… 27.221.28.174, 121.29.54.21, 14.204.144.173, …
Connecting to xihajun.com (xihajun.com)|27.221.28.174|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 125556 (123K) [text/html]
Saving to: `index.html’100%[=====================================>] 125,556 168K/s in 0.7s
2017-04-05 06:18:15 (168 KB/s) – `index.html’ saved [125556/125556]
下载了index.html文件,如果想要将将文件重命名(比如命名为xiha.html)可以使用-O参数,具体如下:
wget -c xihajun.com -O xiha.html
–2017-04-05 06:19:09– http://xihajun.com/
Resolving xihajun.com (xihajun.com)… 27.221.28.174, 121.29.54.21, 14.204.144.173, …
Connecting to xihajun.com (xihajun.com)|27.221.28.174|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 125556 (123K) [text/html]
Saving to: `xiha.html’100%[=====================================>] 125,556 163K/s in 0.8s
2017-04-05 06:19:11 (163 KB/s) – `xiha.html’ saved [125556/125556]
下载比较大的文件或者网速慢的时候会遇到中断连接的情况,这时候-c参数,就是断电续传功能是一个不错的选择
wget -c http://xihajun.com
当然还可以设定超时次数用-t(times来指定)
还有比较强悍的批量下载功能,可以将想要下载的链接存到一个文件中,之后使用参数-i批量对文件里每行给出的链接进行下载,功能还是很强悍的
比如我把链接文件存为a,a中内容如下(发现其中开头有空格的可以正常下载,而其余文字(带引号都)不行,不加http://也不能正常下载)
test
test xihajun.com
http://xihajun.com
http://xihajun.com test
http://xihajun.com
xihajun.com
xihajun.com
结果如下:
a: Invalid URL test: Scheme missing
a: Invalid URL test xihajun.com: Scheme missing
a: Invalid URL xihajun.com: Scheme missing
a: Invalid URL xihajun.com: Scheme missing
–2017-04-05 06:38:56– http://xihajun.com/
Resolving xihajun.com (xihajun.com)… 121.29.54.21, 14.204.144.173, 101.69.121.35, …
Connecting to xihajun.com (xihajun.com)|121.29.54.21|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 125556 (123K) [text/html]
Saving to: `index.html.2′100%[=====================================>] 125,556 156K/s in 0.8s2017-04-05 06:39:01 (156 KB/s) – `index.html.2′ saved [125556/125556]–2017-04-05 06:39:01– http://xihajun.com/
Reusing existing connection to xihajun.com:80.
HTTP request sent, awaiting response… 200 OK
Length: 125556 (123K) [text/html]
Saving to: `index.html.3′100%[=====================================>] 125,556 –.-K/s in 0s2017-04-05 06:39:01 (472 MB/s) – `index.html.3′ saved [125556/125556]–2017-04-05 06:39:01– http://xihajun.com%20test/
Resolving xihajun.com test (xihajun.com test)… failed: Name or service not known.
wget: unable to resolve host address `xihajun.com test’
FINISHED –2017-04-05 06:39:01–
Total wall clock time: 4.8s
Downloaded: 2 files, 245K in 0.8s (312 KB/s)
至于能不能批量重命名呢,嘻哈也不太清楚了,可能需要写脚本之类的。
参考文章:Wget用法、参数解释的比较好的一个文章
欢迎转载:注明转载出处就好:):嘻哈小屋 » 【充电】linux学习(四)——wget命令