10 Linux Wget命令示例
# rpm -qa wget wget-1.12-1.4.el6.i686请 wget的情况下使用 YUM命令尚未安装安装它,或者你也可以下载二进制包 http://ftp.gnu.org/gnu/wget/ 。
# yum -y install wget这里使用的 -y选项,是为了防止确认提示安装任何包之前。 欲了解更多 YUM命令示例和选项阅读文章 为Linux软件包管理YUM 20命令示例 。
单文件下载
该命令将下载单个文件并存储在当前目录中。它还显示 下载进度 , 大小 , 日期和 时间在下载。# wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz --2012-10-02 11:28:30-- http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b Connecting to ftp.gnu.org|208.118.235.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 446966 (436K) [application/x-gzip] Saving to: wget-1.5.3.tar.gz 100%[===================================================================================>] 446,966 60.0K/s in 7.4s 2012-10-02 11:28:38 (58.9 KB/s) - wget-1.5.3.tar.gz
2.下载不同名称的文件
使用 -O( 大写 )选项,下载文件用不同的文件名。 在这里,我们给 wget.zip文件名,如下所示。# wget -O wget.zip http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz --2012-10-02 11:55:54-- http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b Connecting to ftp.gnu.org|208.118.235.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 446966 (436K) [application/x-gzip] Saving to: wget.zip 100%[===================================================================================>] 446,966 60.0K/s in 7.5s 2012-10-02 11:56:02 (58.5 KB/s) - wget.zip
3.使用http和ftp协议下载多个文件
在这里,我们看到如何使用 HTTP和 FTP协议用 wget命令在那些下载多个文件。# wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz ftp://ftp.gnu.org/gnu/wget/wget-1.10.1.tar.gz.sig --2012-10-02 12:11:16-- http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b Connecting to ftp.gnu.org|208.118.235.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 446966 (436K) [application/x-gzip] Saving to: wget-1.5.3.tar.gz 100%[===================================================================================>] 446,966 56.7K/s in 7.6s 2012-10-02 12:11:29 (57.1 KB/s) - wget-1.5.3.tar.gz --2012-10-02 12:11:29-- ftp://ftp.gnu.org/gnu/wget/wget-1.10.1.tar.gz.sig => wget-1.10.1.tar.gz.sig Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD (1) /gnu/wget ... done. ==> SIZE wget-1.10.1.tar.gz.sig ... 65 ==> PASV ... done. ==> RETR wget-1.10.1.tar.gz.sig ... done. Length: 65 (unauthoritative) 100%[===================================================================================>] 65 --.-K/s in 0s 2012-10-02 12:11:33 (2.66 MB/s) - wget-1.10.1.tar.gz.sig FINISHED --2012-10-02 12:11:33-- Downloaded: 2 files, 437K in 7.6s (57.1 KB/s)
4.从文件中读取URL
您可以存储 网址的数量在文本文件中,并与 -i选项进行下载。 下面我们在这里我们把一系列 的URL中下载wget的目录下创建 tmp.txt。# wget -i /wget/tmp.txt --2012-10-02 12:34:12-- http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz ftp://ftp.gnu.org/gnu/wget/wget-1.10.1.tar.gz.sig Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b Connecting to ftp.gnu.org|208.118.235.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 446966 (436K) [application/x-gzip] Saving to: wget-1.10.1.tar.gz.sig 100%[===================================================================================>] 446,966 35.0K/s in 10s 2012-10-02 12:34:23 (42.7 KB/s) - wget-1.10.1.tar.gz.sig --2012-10-02 12:34:23-- http://mirrors.hns.net.in/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveDVD.iso Resolving mirrors.hns.net.in... 111.91.91.34, 2401:4800::111:91:91:34 Connecting to mirrors.hns.net.in|111.91.91.34|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1761607680 (1.6G) [application/octet-stream] Saving to: CentOS-6.3-x86_64-LiveDVD.iso 45%[========================================== ] 1,262,000 51.6K/s eta 8h 17m
5.恢复未完成的下载
在大文件下载的情况下,可能发生的某个时候在这种情况下我们就可以重新下载它被离开与 -c选项相同的文件停止下载。 但是当你开始下载文件,而无需指定 -c选项 的wget将在文件的末尾添加扩展 .1,考虑到作为一个新的下载。 所以,这是很好的做法,当你下载大文件添加 -c开关。# wget -c http://mirrors.hns.net.in/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveDVD.iso --2012-10-02 12:46:57-- http://mirrors.hns.net.in/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveDVD.iso Resolving mirrors.hns.net.in... 111.91.91.34, 2401:4800::111:91:91:34 Connecting to mirrors.hns.net.in|111.91.91.34|:80... connected. HTTP request sent, awaiting response... 206 Partial Content Length: 1761607680 (1.6G), 1758132697 (1.6G) remaining [application/octet-stream] Saving to: CentOS-6.3-x86_64-LiveDVD.iso 51% [================================================= ] 3,877,262 47.0K/s eta 10h 27m ^
6.在文件名中下载带有.1的文件
当您启动下载没有 -c选项 的wget在文件的最后添加 .1,并用新鲜的下载启动。 如果 .1已经存在于文件的最后 0.2追加。# wget http://mirrors.hns.net.in/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveDVD.iso --2012-10-02 12:50:49-- http://mirrors.hns.net.in/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveDVD.iso Resolving mirrors.hns.net.in... 111.91.91.34, 2401:4800::111:91:91:34 Connecting to mirrors.hns.net.in|111.91.91.34|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1761607680 (1.6G) [application/octet-stream] Saving to: CentOS-6.3-x86_64-LiveDVD.iso.1 18% [================== ] 172,436 59.2K/s参见示例文件 .1扩展名的文件的末尾。
# ls -l CentOS* -rw-r--r--. 1 root root 3877262 Oct 2 12:47 CentOS-6.3-x86_64-LiveDVD.iso -rw-r--r--. 1 root root 181004 Oct 2 12:50 CentOS-6.3-x86_64-LiveDVD.iso.1
7.在后台下载文件
用 -B选项就可以开始下载和日志都写在 /wget/log.txt文件后立即派在后台下载。# wget -b /wget/log.txt ftp://ftp.iinet.net.au/debian/debian-cd/6.0.5/i386/iso-dvd/debian-6.0.5-i386-DVD-1.iso Continuing in background, pid 3550.
8.限制下载速度限制
随着选项 -limit率= 100K,下载速度限定为100K和日志将在 /wget/log.txt如下图所示创建。# wget -c --limit-rate=100k /wget/log.txt ftp://ftp.iinet.net.au/debian/debian-cd/6.0.5/i386/iso-dvd/debian-6.0.5-i386-DVD-1.iso /wget/log.txt: Scheme missing. --2012-10-02 13:16:21-- ftp://ftp.iinet.net.au/debian/debian-cd/6.0.5/i386/iso-dvd/debian-6.0.5-i386-DVD-1.iso => debian-6.0.5-i386-DVD-1.iso esolving ftp.iinet.net.au... 203.0.178.32 Connecting to ftp.iinet.net.au|203.0.178.32|:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD (1) /debian/debian-cd/6.0.5/i386/iso-dvd ... done. ==> SIZE debian-6.0.5-i386-DVD-1.iso ... 4691312640 ==> PASV ... done. ==> REST 2825236 ... done. ==> RETR debian-6.0.5-i386-DVD-1.iso ... done. Length: 4688487404 (4.4G), 4685662168 (4.4G) remaining (unauthoritative) 0% [ ] 3,372,160 35.5K/s eta 28h 39m
9.使用用户名和密码限制FTP和HTTP下载
随着选项 -http用户=用户名 ,-http密码=密码 &-ftp用户=用户名 ,-ftp密码=密码 ,您可以下载密码限制 HTTP或 FTP站点,如下图所示。# wget --http-user=narad --http-password=password http://mirrors.hns.net.in/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveDVD.iso
# wget --ftp-user=narad --ftp-password=password ftp://ftp.iinet.net.au/debian/debian-cd/6.0.5/i386/iso-dvd/debian-6.0.5-i386-DVD-1.iso
10.查找wget版本和帮助
随着选项 -version和 -help可以查看 版本,并在需要时 提供帮助 。# wget --version # wget --help在这篇文章中我们已经介绍了与日常管理任务选项的Linux 的wget命令 。 做 男人wget的 ,如果你婉更多地了解它。请通过我们的评论框分享,或者如果我们错过了任何东西,请让我们知道。