生活随笔
收集整理的這篇文章主要介紹了
linux常用命令:wget 命令
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
wget命令用來從指定的URL下載文件。wget非常穩定,它在帶寬很窄的情況下和不穩定網絡中有很強的適應性,如果是由于網絡的原因下載失敗,wget會不斷的嘗試,直到整個文件下載完畢。如果是服務器打斷下載過程,它會再次聯到服務器上從停止的地方繼續下載。這對從那些限定了鏈接時間的服務器上下載大文件非常有用。
1.命令格式:
wget? [參數]? [URL]
2.命令功能:
wget命令用來從指定的URL下載文件。
3.命令參數:
1)? -O --output-document=FILE 將文檔寫入 FILE,等價于給文檔指定名稱,為下載文件指定名稱
2) --limit-rate=[n] ? 限速下載,n為指定下載的速度
3) -c ? 支持斷點續傳
4) -i 同時下載多個文件
5) -Q?? [n] ? 當下載文件大小超過n時退出下載
6) -o? 把下載信息存入日志文件
7) -P 指定下載目錄
8) --tries=n 測試下載次數
9)-b 后臺下載
4.使用實例:
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.
1500K .......... .......... .......... .......... .......... 0%
109K 15m12s550K .......... .......... .......... .......... .......... 0%
148K 14m29s600K .......... .......... .......... .......... .......... 1%
137K 13m55s650K .......... .......... .......... .......... .......... 1%
108K 13m34s700K .......... .......... .......... .......... .......... 1%
88.4K 13m24s750K .......... .......... .......... .......... .......... 1%
102K 13m10s800K .......... .......... .......... .......... .......... 1%
102K 12m57s850K .......... .......... .......... .......... .......... 1%
81.2K 12m54s900K .......... .......... .......... .......... .......... 1%
85.3K 12m50s950K .......... .......... .......... .......... .......... 1%
21.7K 14m28s1000K .......... .......... .......... .......... .......... 1%
24.1K 15m43s1050K .......... .......... .......... .......... .......... 1%
80.4K 15m33s1100K .......... .......... .......... .......... .......... 1%
91.4K 15m20s1150K .......... .......... .......... .......... .......... 1%
126K 15m0s1200K .......... .......... .......... .......... .......... 2%
127K 14m42s1250K .......... .......... .......... .......... .......... 2%
34.4K 15m14s1300K .......... .....^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
?
轉載于:https://www.cnblogs.com/shujuxiong/p/9013246.html
總結
以上是生活随笔為你收集整理的linux常用命令:wget 命令的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。