mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-23 21:20:42 +08:00
[Translated] 20141009 Linux or Unix wget command with practical examples.md
This commit is contained in:
parent
f32267d73a
commit
0d0e2b878e
@ -1,128 +0,0 @@
|
||||
Translating by GOLinux ...
|
||||
Linux/UNIX wget command with practical examples
|
||||
================================================================================
|
||||
wget is a Linux/UNIX command line **file downloader**.Wget is a free utility for non-interactive download of files from the Web. It supports **HTTP**, **HTTPS**, and **FTP** protocols, as well as retrieval through HTTP proxies.Wget is non-interactive, meaning that it can work in the background, while the user is not logged on.
|
||||
|
||||
In this post we will discuss different examples of wget command.
|
||||
|
||||
### Example:1 Download Single File ###
|
||||
|
||||
# wget http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
|
||||
|
||||
This command will download the CentOS 7 ISO file in the user’s current working directtory.
|
||||
|
||||
### Example:2 Resume Partial Downloaded File ###
|
||||
|
||||
There are some scenarios where we start downloading a large file but in the middle Internet got disconnected , so using the option ‘**-c**’ in wget command we can resume our download from where it got disconnected.
|
||||
|
||||
# wget -c http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
|
||||
|
||||
![](http://www.linuxtechi.com/wp-content/uploads/2014/09/wget-resume-download-1024x111-1.jpg)
|
||||
|
||||
### Example:3 Download Files in the background ###
|
||||
|
||||
We can download the file in the background using the option ‘-b’ in wget command.
|
||||
|
||||
linuxtechi@localhost:~$ wget -b http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/
|
||||
CentOS-7.0-1406-x86_64-DVD.iso
|
||||
Continuing in background, pid 4505.
|
||||
Output will be written to ‘wget-log’.
|
||||
|
||||
As we can see above that downloading progress is capture in ‘wget-log’ file in user’s current directory.
|
||||
|
||||
linuxtechi@localhost:~$ tail -f wget-log
|
||||
2300K ………. ………. ………. ………. ………. 0% 48.1K 18h5m
|
||||
2350K ………. ………. ………. ………. ………. 0% 53.7K 18h9m
|
||||
2400K ………. ………. ………. ………. ………. 0% 52.1K 18h13m
|
||||
2450K ………. ………. ………. ………. ………. 0% 58.3K 18h14m
|
||||
2500K ………. ………. ………. ………. ………. 0% 63.6K 18h14m
|
||||
2550K ………. ………. ………. ………. ………. 0% 63.4K 18h13m
|
||||
2600K ………. ………. ………. ………. ………. 0% 72.8K 18h10m
|
||||
2650K ………. ………. ………. ………. ………. 0% 59.8K 18h11m
|
||||
2700K ………. ………. ………. ………. ………. 0% 52.8K 18h14m
|
||||
2750K ………. ………. ………. ………. ………. 0% 58.4K 18h15m
|
||||
2800K ………. ………. ………. ………. ………. 0% 58.2K 18h16m
|
||||
2850K ………. ………. ………. ………. ………. 0% 52.2K 18h20m
|
||||
|
||||
### Example:4 Limiting Download Speed . ###
|
||||
|
||||
By default wget command try to use full bandwidth , but there may be case that you are using shared internet , so if you try to download huge file using wget , this may slow down Internet of other users. This situation can be avoided if you limit the download speed using ‘–limit-rate‘ option.
|
||||
|
||||
#wget --limit-rate=100k http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
|
||||
|
||||
In the above example,the download speed is limited to 100k.
|
||||
|
||||
### Example:5 Download Multiple Files using ‘-i’ option ###
|
||||
|
||||
If you want to download multiple files using wget command , then first create a text file and add all URLs in the text file.
|
||||
|
||||
# cat download-list.txt
|
||||
url1
|
||||
url2
|
||||
url3
|
||||
url4
|
||||
|
||||
Now issue issue below Command :
|
||||
|
||||
# wget -i download-list.txt
|
||||
|
||||
### Example:6 Increase Retry Attempts. ###
|
||||
|
||||
We can increase the retry attempts using ‘–tries‘ option in wget. By default wget command retries 20 times to make the download successful.
|
||||
|
||||
This option becomes very useful when you have internet connection problem and you are downloading a large file , then there is a chance of failures in the download.
|
||||
|
||||
# wget --tries=75 http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
|
||||
|
||||
### Example:7 Redirect wget Logs to a log File using -o ###
|
||||
|
||||
We can redirect the wget command logs to a log file using ‘-o‘ option.
|
||||
|
||||
#wget -o download.log http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
|
||||
|
||||
Download.log file will be created in the user’s current directory.
|
||||
|
||||
### Example:8 Download Full website for local viewing. ###
|
||||
|
||||
# wget --mirror -p --convert-links -P ./<Local-Folder> website-url
|
||||
|
||||
Whereas
|
||||
|
||||
- **–mirror** : turn on options suitable for mirroring.
|
||||
- **-p** : download all files that are necessary to properly display a given HTML page.
|
||||
- **–convert-links** : after the download, convert the links in document for local viewing.
|
||||
- -**P ./Local-Folder** : save all the files and directories to the specified directory.
|
||||
|
||||
### Example:9 Reject file types while downloading. ###
|
||||
|
||||
When you are planning to download full website , then we can force wget command not to download images using ‘–reject’ option .
|
||||
|
||||
# wget --reject=png Website-To-Be-Downloaded
|
||||
|
||||
### Example:10 Setting Download Quota using wget -Q ###
|
||||
|
||||
We can force wget command to quit downloading when download size exceeds certain size using ‘-Q’ option
|
||||
|
||||
# wget -Q10m -i download-list.txt
|
||||
|
||||
Note that quota will never affect downloading a single file. So if you specify wget -Q10m ftp://wuarchive.wustl.edu/ls-lR.gz, all of the ls-lR.gz will be downloaded. The same goes even when several URLs are specified on the command-line. However, quota is respected when retrieving either recursively, or from an input file. Thus you may safely type ‘wget -Q10m -i download-list.txt’ download will be aborted when the quota is exceeded.
|
||||
|
||||
### Example:11 Downloading file from password protected site. ###
|
||||
|
||||
# wget --ftp-user=<user-name> --ftp-password=<password> Download-URL
|
||||
|
||||
Another way to specify username and password is in the URL itself.
|
||||
|
||||
Either method reveals your password to anyone who bothers to run “ps”. To prevent the passwords from being seen, store them in .wgetrc or .netrc, and make sure to protect those files from other users with “chmod”. If the passwords are really important, do not leave them lying in those files either edit the files and delete them after Wget has started the download.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.linuxtechi.com/wget-command-practical-examples/
|
||||
|
||||
作者:[Pradeep Kumar][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.linuxtechi.com/author/pradeep/
|
@ -1,43 +0,0 @@
|
||||
|
||||
生日快乐,Linux! 1991年8月25日,Linus Torvalds 开启新的篇章。
|
||||
================================================================================
|
||||
![Linus Torvalds](http://i1-news.softpedia-static.com/images/news2/Linus-Torvalds-Started-a-Revolution-on-August-25-1991-Happy-Birthday-Linux-456212-2.jpg)
|
||||
Linus Torvalds
|
||||
|
||||
**Linux工程刚刚进入第23个年头。有着成千上万的人一起开源的努力,Linux 现在是全世界最大的合作结晶。**
|
||||
|
||||
时光倒流到1991年,一个名字叫Linus Torvalds的程序员想开发一个免费的操作系统。当时他并没有打算把这个软件做得像GNU工程那么大,他做这个工程仅仅是因为他的爱好。他开始研发的东西变成了全世界最成功的操作系统,但是在当时没有人可以想像这个东西是什么样子的。
|
||||
|
||||
Linus Torvalds 在1991年8月25日发了一封邮件。邮件内容是请求帮助测试他新开发的操作系统。尽管那时候他的软件还没改变太多,但是他仍然坚持发送Linux更新发布的邮件。那个时候他的软件还没有被命名为Linux。
|
||||
|
||||
“我正在做一个(免费的)386(486)先进技术处理器操作系统(仅仅是为了个人喜好,不会像GNU那样大和专业)。” 自从4月份,我已经酝酿这个想法,并且已经开始准备好了。我很乐意听见各种关于喜欢与不喜欢minix的反馈,因为我的操作系统(在文件管理系统的物理层面(由于实际的原因)或者在其他方面)于它(minix)相似。最近,我发布了bash(1.08)版本和gcc(1.40)版本,暂时来说它们运行正常。
|
||||
|
||||
“这意味着在未来几个月内,我会得到一些实际的东西。与此同时,我很乐意
|
||||
知道用户希望添加哪些功能。任何建议都是可以,但是我不保证都会去开发它们 :-) 附言:嗯-它是不受限于任何minix代码,并且它有多线程的文件系统。 它不是很轻便(使用386任务交互等), 它可能永远都不会支持任何设备,除了先进的硬盘。 这就是目前为止我所知道的。 :-(. " [发信人][1] Linus Torvalds.
|
||||
|
||||
一切都是由这封邮件开始的,很有趣的是从那时候起已经可以感受到东西是怎么养逐步形成的。Linux操作系统不仅赶上了时代的步伐,尤其是在服务器市场上,而且强大的Linux覆盖了其他领域。
|
||||
|
||||
事实上,现在已经很难去寻找一个技术还没有被Linus操作系统影响的。手机,电视,冰箱,微型电脑,操纵台,平板电脑,基本每一个带有电子芯片都是可以运行Linux或者它已经安装了一些以Linux为基础研发的操作系统。
|
||||
|
||||
Linux无处不在,它已经覆盖了无数的设备,并且它的影响力以每年幂指数的数率增长。你可能认为Linus(先生)是世界上最有财富的人,但是不要忘记了,Linux是一个免费的软件。每个人都可以使用它,修改它,甚至以它为赚钱的工具。他(Linus)做这个不是为了金钱。
|
||||
|
||||
Linus Torvalds 在1991年开启的时代的改革,但是这个改革还没有结束。 实际上,你可以认为这仅仅是个开始。
|
||||
|
||||
> 生日快乐,Linux!请加入我们庆祝一个已经改变世界的免费操作系统的23岁生日。[pic.twitter.com/mTVApV85gD][2]
|
||||
>
|
||||
> — The Linux Foundation (@linuxfoundation) [August 25, 2014][3]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://news.softpedia.com/news/Linus-Torvalds-Started-a-Revolution-on-August-25-1991-Happy-Birthday-Linux-456212.shtml
|
||||
|
||||
作者:[Silviu Stahie][a]
|
||||
译者:[Shaohao Lin](https://github.com/shaohaolin)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://news.softpedia.com/editors/browse/silviu-stahie
|
||||
[1]:https://groups.google.com/forum/#!original/comp.os.minix/dlNtH7RRrGA/SwRavCzVE7gJ
|
||||
[2]:http://t.co/mTVApV85gD
|
||||
[3]:https://twitter.com/linuxfoundation/statuses/503799441900314624
|
@ -0,0 +1,127 @@
|
||||
Linux/Unix wget命令实例
|
||||
================================================================================
|
||||
wget是Linux/Unix命令行**文件下载器**,它是下载网站上文件的免费的非交互下载工具,它支持**HTTP**、**HTTPS**和**FTP**协议,也支持通过HTTP代理检索。Wget是非交互的,这就是说它可以在用户没有登录到系统时在后台工作。
|
||||
|
||||
在本帖中,我们将讨论wget命令的一些不同使用实例。
|
||||
|
||||
### 实例:1 下载单个文件 ###
|
||||
|
||||
# wget http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
|
||||
|
||||
该命令会下载CentOS 7 ISO文件到用户当前工作目录中。
|
||||
|
||||
### 实例:2 续传分段下载文件 ###
|
||||
|
||||
总有那么一些场景,当我们开始下载一个大文件时,中途互联网却断开了。那样的话,我们可以使用wget命令的‘**-c**’选项,让下载从断点续传。
|
||||
|
||||
# wget -c http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
|
||||
|
||||
![](http://www.linuxtechi.com/wp-content/uploads/2014/09/wget-resume-download-1024x111-1.jpg)
|
||||
|
||||
### 实例:3 后台下载文件 ###
|
||||
|
||||
我们可以通过在wget命令中使用‘-b’选项来让它在后台下载文件。
|
||||
|
||||
linuxtechi@localhost:~$ wget -b http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/
|
||||
CentOS-7.0-1406-x86_64-DVD.iso
|
||||
Continuing in background, pid 4505.
|
||||
Output will be written to ‘wget-log’.
|
||||
|
||||
正如我们上面所见,下载进程被捕获到用户当前目录中的‘wget-log’文件中。
|
||||
|
||||
linuxtechi@localhost:~$ tail -f wget-log
|
||||
2300K ………. ………. ………. ………. ………. 0% 48.1K 18h5m
|
||||
2350K ………. ………. ………. ………. ………. 0% 53.7K 18h9m
|
||||
2400K ………. ………. ………. ………. ………. 0% 52.1K 18h13m
|
||||
2450K ………. ………. ………. ………. ………. 0% 58.3K 18h14m
|
||||
2500K ………. ………. ………. ………. ………. 0% 63.6K 18h14m
|
||||
2550K ………. ………. ………. ………. ………. 0% 63.4K 18h13m
|
||||
2600K ………. ………. ………. ………. ………. 0% 72.8K 18h10m
|
||||
2650K ………. ………. ………. ………. ………. 0% 59.8K 18h11m
|
||||
2700K ………. ………. ………. ………. ………. 0% 52.8K 18h14m
|
||||
2750K ………. ………. ………. ………. ………. 0% 58.4K 18h15m
|
||||
2800K ………. ………. ………. ………. ………. 0% 58.2K 18h16m
|
||||
2850K ………. ………. ………. ………. ………. 0% 52.2K 18h20m
|
||||
|
||||
### 实例:4 限制下载速率 ###
|
||||
|
||||
默认情况下,wget命令尝试以全速下载,但是有时候你可能使用的是共享互联网,那么如果你尝试使用wget来下载庞大的文件时,就会把其它用户的网络拖慢。这时,你如果使用‘-limit-rate’选项来限制下载速率,就可以避免这种情况的发生。
|
||||
|
||||
#wget --limit-rate=100k http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
|
||||
|
||||
在上例中,下载速率被限制到了100k。
|
||||
|
||||
### 实例:5 使用‘-i’选项来下载多个文件 ###
|
||||
|
||||
如果你想要使用wget命令来下载多个文件,那么首先要创建一个文本文件,并将所有的URL添加到该文件中。
|
||||
|
||||
# cat download-list.txt
|
||||
url1
|
||||
url2
|
||||
url3
|
||||
url4
|
||||
|
||||
现在,发出以下命令吧:
|
||||
|
||||
# wget -i download-list.txt
|
||||
|
||||
### 实例:6 增加重试次数 ###
|
||||
|
||||
我们可以使用‘-tries’选项来增加重试次数。默认情况下,wget命令会重试20次以使下载成功。
|
||||
|
||||
该选项在你下载一个大文件的过程中互联网连接发生问题时十分有用,因为在那种情况下,会增加下载失败的几率。
|
||||
|
||||
# wget --tries=75 http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
|
||||
|
||||
### 实例:7 使用-o选项来重定向wget日志到文件 ###
|
||||
|
||||
我们可以使用‘-o’选项来重定向wget命令的日志到一个日志文件。
|
||||
|
||||
#wget -o download.log http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
|
||||
|
||||
上面的命令会在用户当前目录下创建download.log文件。
|
||||
|
||||
### 实例:8 下载整个网站用于本地查看 ###
|
||||
|
||||
# wget --mirror -p --convert-links -P ./<Local-Folder> website-url
|
||||
|
||||
鉴于
|
||||
|
||||
- **–mirror** : 开启适用于镜像的选项。
|
||||
- **-p** : 下载所有能正确显示指定HTML网页的全部必要文件。
|
||||
- **–convert-links** : 下载完成后,转换文档中的链接以用于本地查看。
|
||||
- -**P ./Local-Folder** : 保存所有文件和目录到指定的目录。
|
||||
|
||||
### 实例:9 下载过程中拒绝文件类型 ###
|
||||
|
||||
当你正打算下载整个网站时,我们可以使用‘-reject’选项来强制wget不下载图片。
|
||||
|
||||
# wget --reject=png Website-To-Be-Downloaded
|
||||
|
||||
### 实例:10 使用wget -Q设置下载配额 ###
|
||||
|
||||
我们可以使用‘-Q’选项强制wget命令在下载大小超过特定大小时退出下载。
|
||||
|
||||
# wget -Q10m -i download-list.txt
|
||||
|
||||
注意,配额不会对单个文件的下载产生影响。所以,如果你指定wget -Q10m ftp://wuarchive.wustl.edu/ls-lR.gz,ls-lR的全部内容都会被下载。这在下载命令行指定的多个URL时也一样。然而,在递归或从一个输入文件检索时,还是值得一用。因此,你可以安全地输入‘wget -Q10m -i download-list.txt’,在超过配额时,下载会退出。
|
||||
|
||||
### 实例:11 从密码保护的网站下载文件 ###
|
||||
|
||||
# wget --ftp-user=<user-name> --ftp-password=<password> Download-URL
|
||||
|
||||
另外一种指定用户名和密码的方式是在URL中。
|
||||
|
||||
任一方法都将你的密码揭露给了那些运行“ps”命令的人。要防止密码被查看到,将它们存储到.wgetrc或.netrc中,并使用“chmod”设置合适的权限来保护这些文件不让其他用户查看到。如果密码真的很重要,不要在它们还在文件里躺着的时候走开,在Wget开始下载后,编辑该文件,或者删除它们。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.linuxtechi.com/wget-command-practical-examples/
|
||||
|
||||
作者:[Pradeep Kumar][a]
|
||||
译者:[GOLinux](https://github.com/GOLinux)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.linuxtechi.com/author/pradeep/
|
Loading…
Reference in New Issue
Block a user