您的位置:首页 > 运维架构 > Linux

每天一个Linux命令(59)wget命令

2016-06-26 08:28 621 查看
[b] wget命令用来从指定的URL下载文件。[/b]

[b] (1)用法:[/b]

[b] 用法: wget [参数] [URL][/b]

[b] (2)功能:[/b]

[b] 功能: wget命令用来从指定的URL下载文件。wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性,如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕。如果是服务器打断下载过程,它会再次联到服务器上从停止的地方继续下载。这对从那些限定了链接时间的服务器上下载大文件非常有用。
[/b]

[b] (3)选项参数:[/b]

1) -O --output-document=FILE             将文档写入 FILE,等价于给文档指定名称

2) --limit-rate=
                   限速下载,n为指定下载的速度


3) -c                          支持断点续传

4) -i                           同时下载多个文件

5) -Q
                        当下载文件大小超过n时退出下载            


6) -o                           把下载信息存入日志文件 


7) -P                           指定目录下载


8) --tries=n                       测试下载次数


[b] (4)实例:[/b]

1)[root@localhost ~]# wget http://files.cnblogs.com/files/MenAngel/GLTools-master.zip   直接从网址下载文件
[root@localhost ~]# wget http://files.cnblogs.com/files/MenAngel/GLTools-master.zip --2016-06-23 02:31:01--  http://files.cnblogs.com/files/MenAngel/GLTools-master.zip 正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:64789 (63K) [application/x-zip-compressed]
正在保存至: “GLTools-master.zip”

100%[===================================================================>] 64,789      --.-K/s 用时 0.1s

2016-06-23 02:31:08 (444 KB/s) - 已保存 “GLTools-master.zip” [64789/64789])

[root@localhost ~]# find -name "GLTools-master.zip"      //查看下载的文件存放的位置      
./GLTools-master.zip
[root@localhost ~]# ls -l                     //默认存放在当前目录下
总用量 68
-rw-------. 1 root root  2748 6月  21 11:30 anaconda-ks.cfg
-rw-r--r--. 1 root root 64789 6月  22 01:42 GLTools-master.zip


2)[root@localhost ~]# wget -O GL_O http://files.cnblogs.com/files/MenAngel/GLTools-master.zip  为下载的文件指定别名

[root@localhost ~]# wget -O GL_O http://files.cnblogs.com/files/MenAngel/GLTools-master.zip --2016-06-23 02:36:33--  http://files.cnblogs.com/files/MenAngel/GLTools-master.zip 正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:64789 (63K) [application/x-zip-compressed]
正在保存至: “GL_O”

100%[===================================================================>] 64,789       364KB/s 用时 0.2s

2016-06-23 02:36:38 (364 KB/s) - 已保存 “GL_O” [64789/64789])

[root@localhost ~]# ll
总用量 132
-rw-------. 1 root root  2748 6月  21 11:30 anaconda-ks.cfg
-rw-r--r--. 1 root root 64789 6月  22 01:42 GL_O
-rw-r--r--. 1 root root 64789 6月  22 01:42 GLTools-master.zip


3)[root@localhost ~]# wget --limit-rate=200k http://files.cnblogs.com/files/MenAngel/GLTools-master.zip    限速下载
[root@localhost ~]# wget --limit-rate=200k http://files.cnblogs.com/files/MenAngel/GLTools-master.zip        //注意速率单位,默认情况下是bit/s --2016-06-23 02:39:34--  http://files.cnblogs.com/files/MenAngel/GLTools-master.zip 正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:64789 (63K) [application/x-zip-compressed]
正在保存至: “GLTools-master.zip.2”

100%[===================================================================>] 64,789      --.-K/s 用时 0.1s

2016-06-23 02:39:40 (435 KB/s) - 已保存 “GLTools-master.zip.2” [64789/64789])


4)[root@localhost ~]# wget --limit-rate=1k -c http://files.cnblogs.com/files/MenAngel/GLTools-master.zip    断点续传
[root@localhost ~]# wget --limit-rate=1k -c http://files.cnblogs.com/files/MenAngel/GLTools-master.zip --2016-06-23 03:05:43--  http://files.cnblogs.com/files/MenAngel/GLTools-master.zip 正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:64789 (63K) [application/x-zip-compressed]
正在保存至: “GLTools-master.zip”

16% [=========>                                                          ] 10,429      1024B/s 剩余 53s     ^Z
[2]+  已停止               wget --limit-rate=1k -c http://files.cnblogs.com/files/MenAngel/GLTools-master.zip [root@localhost ~]# wget --limit-rate=1k -c http://files.cnblogs.com/files/MenAngel/GLTools-master.zip --2016-06-23 03:06:00--  http://files.cnblogs.com/files/MenAngel/GLTools-master.zip 正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 206 Partial Content
长度:64789 (63K),剩余 54236 (53K) [application/x-zip-compressed]
正在保存至: “GLTools-master.zip”
17%  [=========>   //直接从先前断的地方开始


5)[root@localhost ~]# wget -b url         在后台下载

6)[root@localhost ~]# tail -f wget-log.1      查看文件下载的进度(动态的)


[root@localhost ~]# wget -b http://jsdx.down.chinaz.com/201209/MySQL-embedded-5.5.28-1.linux2.6.i386.rpm 继续在后台运行,pid 为 50518。
将把输出写入至 “wget-log.1”。
[root@localhost ~]# tail -f wget-log.1
500K .......... .......... .......... .......... ..........  0%  109K 15m12s
550K .......... .......... .......... .......... ..........  0%  148K 14m29s
600K .......... .......... .......... .......... ..........  1%  137K 13m55s
650K .......... .......... .......... .......... ..........  1%  108K 13m34s
700K .......... .......... .......... .......... ..........  1% 88.4K 13m24s
750K .......... .......... .......... .......... ..........  1%  102K 13m10s
800K .......... .......... .......... .......... ..........  1%  102K 12m57s
850K .......... .......... .......... .......... ..........  1% 81.2K 12m54s
900K .......... .......... .......... .......... ..........  1% 85.3K 12m50s
950K .......... .......... .......... .......... ..........  1% 21.7K 14m28s
1000K .......... .......... .......... .......... ..........  1% 24.1K 15m43s
1050K .......... .......... .......... .......... ..........  1% 80.4K 15m33s
1100K .......... .......... .......... .......... ..........  1% 91.4K 15m20s
1150K .......... .......... .......... .......... ..........  1%  126K 15m0s
1200K .......... .......... .......... .......... ..........  2%  127K 14m42s
1250K .......... .......... .......... .......... ..........  2% 34.4K 15m14s
1300K .......... .....^Z


7)[root@localhost ~]# wget --spider  url      

[root@localhost ~]# wget --spider http://jsdx.down.chinaz.com/201209/MySQL-embedded-5.5.28-1.linux2.6.i386.rpm 开启 Spider 模式。检查是否存在远程文件。
--2016-06-23 03:20:46--  http://jsdx.down.chinaz.com/201209/MySQL-embedded-5.5.28-1.linux2.6.i386.rpm 正在解析主机 jsdx.down.chinaz.com (jsdx.down.chinaz.com)... 182.100.67.10
正在连接 jsdx.down.chinaz.com (jsdx.down.chinaz.com)|182.100.67.10|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:61904663 (59M) [audio/x-pn-realaudio-plugin]
存在远程文件。


你可以在以下几种情况下使用--spider参数:
定时下载之前进行检查
间隔检测网站是否可用
 检查网站页面的死链接


8)同时下载多个文件

cat > filelist.txt
url1
url2
url3
url4
wget -i filelist.txt


9)[root@localhost ~]# wget -o download.log ftp://magnet/?xt=urn:btih:211712D    将下载的输出信息存入日志
[root@localhost ~]# wget -o download.log ftp://magnet/?xt=urn:btih:211712D [root@localhost ~]# cat download.log
--2016-06-23 03:30:06--  ftp://magnet/?xt=urn:btih:211712D => “.listing”
正在解析主机 magnet (magnet)... 失败:未知的名称或服务。
wget: 无法解析主机地址 “magnet”
[root@localhost ~]#


10)[root@localhost ~]# wegt -P /home/sunmeng http://files.cnblogs.com/files/MenAngel/GLTools-master.zip  指定下载目录
[root@localhost ~]# wegt -P /home/sunmeng http://files.cnblogs.com/files/MenAngel/GLTools-master.zip bash: wegt: 未找到命令...
相似命令是: 'wget'
[root@localhost ~]# wget -P /home/sunmeng http://files.cnblogs.com/files/MenAngel/GLTools-master.zip --2016-06-23 03:42:36--  http://files.cnblogs.com/files/MenAngel/GLTools-master.zip 正在解析主机 files.cnblogs.com (files.cnblogs.com)... 120.26.70.206
正在连接 files.cnblogs.com (files.cnblogs.com)|120.26.70.206|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:64789 (63K) [application/x-zip-compressed]
正在保存至: “/home/sunmeng/GLTools-master.zip”

100%[======================================>] 64,789      --.-K/s 用时 0.1s

2016-06-23 03:42:42 (456 KB/s) - 已保存 “/home/sunmeng/GLTools-master.zip” [64789/64789])

[root@localhost ~]# ls -l /home/sunmeng
总用量 64
drwxr-xr-x. 2 sunmeng sunmeng     6 6月  23 02:29 Desktop
drwxr-xr-x. 2 sunmeng sunmeng     6 6月  21 03:31 Documents
drwxr-xr-x. 2 sunmeng sunmeng     6 6月  21 03:31 Downloads
-rw-r--r--. 1 root    root    64789 6月  22 01:42 GLTools-master.zip
drwxr-xr-x. 2 sunmeng sunmeng     6 6月  21 03:31 Music
drwxr-xr-x. 2 sunmeng sunmeng     6 6月  21 03:31 Pictures
drwxr-xr-x. 2 sunmeng sunmeng     6 6月  21 03:31 Public
drwxr-xr-x. 2 sunmeng sunmeng     6 6月  21 03:31 Templates
drwxr-xr-x. 2 sunmeng sunmeng     6 6月  21 03:31 Videos
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: