Linux下载命令wget详解

Stupig posted @ 2010年7月13日 17:32 in Linux with tags linux wget 下载 , 3073 阅读

  wget是在Linux下开发的开放源代码的软件,作者是Hrvoje Niksic,后来被移植到包括Windows在内的各个平台上。它有以下功能和特点:

  1、支持断点下传功能;这一点,也是网络蚂蚁和FlashGet当年最大的卖点,现在,wget也可以使用此功能,那些网络不是太好的用户可以放心了;

  2、同时支持FTP和HTTP下载方式;尽管现在大部分软件可以使用HTTP方式下载,但是,有些时候,仍然需要使用FTP方式下载软件;

  3、支持代理服务器;对安全强度很高的系统而言,一般不会将自己的系统直接暴露在互联网上,所以,支持代理是下载软件必须有的功能;

  4、设置方便简单;可能,习惯图形界面的用户已经不是太习惯命令行了,但是,命令行在设置上其实有更多的优点,最少,鼠标可以少点很多次,也不要担心是否错点鼠标;

  5、程序小,完全免费;程序小可以考虑不计,因为现在的硬盘实在太大了;完全免费就不得不考虑了,即使网络上有很多所谓的免费软件,但是,这些软件的广告却不是我们喜欢的。

  wget虽然功能强大,但是使用起来还是比较简单的,基本的语法是:wget [参数列表] URL。下面就结合具体的例子来说明一下wget的用法:

  1、下载整个http或者ftp站点。

$ wget http://place.your.url/here

  这个命令可以将http://place.your.url/here 首页下载下来。使用-x会强制建立服务器上一模一样的目录,如果使用-nd参数,那么服务器上下载的所有内容都会加到本地当前目录。

$ wget -r http://place.your.url/here

  这个命令会按照递归的方法,下载服务器上所有的目录和文件,实质就是下载整个网站。这个命令一定要小心使用,因为在下载的时候,被下载网站指向的所有地址同 样会被下载,因此,如果这个网站引用了其他网站,那么被引用的网站也会被下载下来!基于这个原因,这个参数不常用。可以用-l number参数来指定下载的层次。例如只下载两层,那么使用-l 2。

  要是您想制作镜像站点,那么可以使用-m参数,例如:

$ wget -m http://place.your.url/here 

  这时wget会自动判断合适的参数来制作镜像站点。此时,wget会登录到服务器上,读入robots.txt并按robots.txt的规定来执行。

  2、断点续传。

  当文件特别大或者网络特别慢的时候,往往一个文件还没有下载完,连接就已经被切断,此时就需要断点续传。wget的断点续传是自动的,只需要使用-c参数,例如:

$ wget -c http://the.url.of/incomplete/file

  使用断点续传要求服务器支持断点续传。-t参数表示重试次数,例如需要重试100次,那么就写-t 100,如果设成-t 0,那么表示无穷次重试,直到连接成功。-T参数表示超时等待时间,例如-T 120,表示等待120秒连接不上就算超时。

  3、批量下载。

  如果有多个文件需要下载,那么可以生成一个文件,把每个文件的URL写一行,例如生成文件download.txt,然后用命令:

$ wget -i download.txt

  这样就会把download.txt里面列出的每个URL都下载下来(如果列的是文件就下载文件,如果列的是网站,那么下载首页)。

  4、选择性的下载。

  可以指定让wget只下载一类文件,或者不下载什么文件。例如:

$ wget -m –reject=gif http://target.web.site/subdirectory

  表示下载http://target.web.site/subdirectory,但是忽略gif文件。–accept=LIST 可以接受的文件类型,–reject=LIST拒绝接受的文件类型。

  5、密码和认证。

  wget只能处理利用用户名/密码方式限制访问的网站,可以利用两个参数:

  -http-user=USER 设置HTTP用户

  -http-passwd=PASS 设置HTTP密码

  对于需要证书做认证的网站,就只能利用其他下载工具了,例如curl。

  6、利用代理服务器进行下载。

  如果用户的网络需要经过代理服务器,那么可以让wget通过代理服务器进行文件的下载。此时需要在当前用户的目录下创建一个.wgetrc文件。文件中可以设置代理服务器:

  http-proxy = 111.111.111.111:8080

  ftp-proxy = 111.111.111.111:8080

  分别表示http的代理服务器和ftp的代理服务器。如果代理服务器需要密码则使用:

  -proxy-user=USER 设置代理用户

  -proxy-passwd=PASS 设置代理密码

  这两个参数。

  使用参数-proxy=on/off 使用或者关闭代理。

  wget还有很多有用的功能,需要用户去挖掘。

  附录:

  命令格式:

  wget [参数列表] [目标软件、网页的网址]

  -V,–version 显示软件版本号然后退出;

  -h,–help 显示软件帮助信息;

  -e,–execute=COMMAND 执行一个”.wgetrc“命令;

  -o,–output-file=FILE 将软件输出信息保存到文件;

  -a,–append-output=FILE 将软件输出信息追加到文件;

  -d,–debug 显示输出信息;

  -q,–quiet 不显示输出信息;

  -i,–input-file=FILE 从文件中取得URL;

  -t,–tries=NUMBER 是否下载次数(0表示无穷次);

  -O,–output-document=FILE 下载文件保存为别的文件名;

  -nc, –no-clobber 不要覆盖已经存在的文件;

  -N,–timestamping 只下载比本地新的文件;

  -T,–timeout=SECONDS 设置超时时间;

  -Y,–proxy=on/off 关闭代理;

  -nd,–no-directories 不建立目录;

  -x,–force-directories 强制建立目录;

  -http-user=USER 设置HTTP用户;

  -http-passwd=PASS 设置HTTP密码;

  -proxy-user=USER 设置代理用户;

  -proxy-passwd=PASS 设置代理密码;

  -r,–recursive 下载整个网站、目录(小心使用);

  -l,–level=NUMBER 下载层次;

  -A,–accept=LIST 可以接受的文件类型;

  -R,–reject=LIST 拒绝接受的文件类型;

  -D,–domains=LIST 可以接受的域名;

  -exclude-domains=LIST 拒绝的域名;

  -L,–relative 下载关联链接;

  -follow-ftp 只下载FTP链接;

  -H,–span-hosts 可以下载外面的主机;

  -I,–include-directories=LIST 允许的目录;

  -X,–exclude-directories=LIST 拒绝的目录。

  中文文档名在平常的情况下会被编码, 但是在–cut-dirs 时又是正常的。

$ wget -r -np -nH –cut-dirs=3 ftp://host/test/测试.txt
$ wget -r -np -nH -nd ftp://host/test/%B4%FA%B8%D5.txt
$ wget “ftp://host/test/*”%B4%FA%B8%D5.txt

  由于不知名的原因,可能是为了避开特殊档名,wget会自动将抓取档名的部分用encode_string处理过,所以该patch就把被encode_string处理成”%3A“这种东西,用decode_string还原成”:“,并套用在目录与档案名称的部分,decode_string是wget内建的函式。

$ wget -t0 -c -nH -x -np -b -m -P /home/sunny/NOD32view/ http://downloads1.kaspersky-labs.com/bases/ -o wget.log
AAA 说:
2021年8月09日 21:15

Great post, and great website. Thanks for the information! Pharmacy Technician certification training online course

BASIT 说:
2021年8月15日 15:19

I read that Post and got it fine and informative. buy old gmail

dfg` 说:
2021年8月22日 17:51

The examples below is definetly for instance glimmer brilliant. Each one of these insignificant issues are built utilizing wide variety of cornerstone knowledge. I spend time these folks a great deal. ทางเข้า ufabet มือถือ

dfg` 说:
2021年8月25日 21:09

Excellent website! I adore how it is easy on my eyes it is. I am questioning how I might be notified whenever a new post has been made. Looking for more new updates. Have a great day! buy youtube likes

dfg` 说:
2021年8月26日 22:44

There's lots of dissertation web-sites on line while you find needless to say recognized in your own webpage. sloty

dfg` 说:
2021年8月30日 15:49

This was really an interesting topic and I kinda agree with what you have mentioned here! bluffton plumbing bluffton sc

dfg` 说:
2021年9月11日 17:00

You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. krt carts

dfg` 说:
2021年9月12日 14:25

Very good written article. It will be supportive to anyone who utilizes it, including me. Keep doing what you are doing – can’r wait to read more posts. 代写会被查出来吗

dfg` 说:
2021年9月13日 15:54

This particular looks for example certainly superb. Most of these slight tips are made using availablility of cosmetic foundation interest. I like to him or her appreciably. 먹튀사이트

dfg` 说:
2021年9月14日 14:22

Great write-up, I am a big believer in commenting on blogs to inform the blog writers know that they’ve added something worthwhile to the world wide web!.. slotomania slot machines and free coins

dfg` 说:
2021年10月07日 23:46

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often. real estate crowdfunding platform software

dfg` 说:
2021年10月14日 21:57

Only strive to mention one's content can be as incredible. This clarity with your post is superb! Thanks a lot, hundreds of along with you should go on the pleasurable get the job done. foxz24

dfg` 说:
2021年10月22日 23:46

Today, I was just browsing along and came upon your blog. Just wanted to say good blog and this article helped me a lot, due to which I have found exactly I was looking. https://www.cialis-store.com/product/2

dfg` 说:
2021年10月28日 22:20

Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have. sildalis 120

satac key dates 说:
2021年11月01日 17:39

메이저사이트 메이저놀이터에서는 스포츠 종목으로 축구,야구,농구에 대한 배팅이 가능하면서 먹튀가 존재하지 않는 사이트를 일컫는 명칭입니다.

dfg` 说:
2021年11月03日 00:50

You have performed a great job on this article. It’s very precise and highly qualitative. You have even managed to make it readable and easy to read. You have some real writing talent. Thank you so much. THC vape juice UK

satac key dates 说:
2021年11月03日 19:58

مانا رشــفة متجــر وتطبيــق الكترونــي مختــص فــي بيــع وتوصيــل ميــاه الشــرب الــى المنــازل او المســاجد او أي مــكان تحددونــه مــن خــال وســائل النقــل التــي نمتلكهــا بالإضافــة الــى مســتودعاتنا المنتشــرة فــي عمــوم المملكــة لضمــان الســرعة والكفــاءة بالعمــل كل ذلــك عــن طريـق تطبيـق بتصميم بسـيط سـهل الإ

satac key dates 说:
2021年11月03日 21:55

best website design & development agency Charlotte NC We're not just another website company. Evolution in technology is continually transforming how businesses operate and how people interact with the world.

satac key dates 说:
2021年11月04日 16:09

soap2day.eus Soap2day is a FREE Movie Streaming site to watch movies and tv series. Soap2dayto, soap2day to, soap 2 day, soaptoday is free and safe to use.

satac key dates 说:
2021年11月04日 21:30

Levizo Information risk management software in UK LEVIZO provide Third-party risk management services in UK, Information security services in UK and Information risk management Services in UK. Contact us today for more details and quotation.

dfg` 说:
2021年11月04日 21:31

Fantastic blog! Do you have any tips and hints for aspiring writers? I’m planning to start my own website soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely overwhelmed .. Any suggestions? Many thanks! situs judi slot online deposit via pulsa 10ribu

dfg` 说:
2021年11月07日 21:11

Thank you for some other informative blog. Where else could I get that type of information written in such an ideal means? I have a mission that I’m just now working on, and I have been at the look out for such information. judi online24jam deposit pulsa tanpa potongan

dfg` 说:
2021年11月08日 20:06

excellent expertise gaining article. This submit is actually the quality on this precious topic. betflik ทางเข้า

dfg` 说:
2021年11月10日 15:32

Absolutely fantastic posting! Lots of useful information and inspiration, both of which we all need!Relay appreciate your work. สูตรบาคาร่าฟรี

dfg` 说:
2021年11月14日 15:17

A very excellent blog post. I am thankful for your blog post. I have found a lot of approaches after visiting your post. poncho women

dfdffd 说:
2021年11月16日 00:34

Your blog has chock-a-block of useful information. I liked your blog's content as well as its look. In my opinion, this is a perfect blog in all aspects. 메이저토토

KVS Model Paper 说:
2022年9月27日 19:51

KVS Sample Paper 2023 Pdf Download for Kendriya Vidyalaya Sangathan Class 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 & 12 Arts, KVS Model Paper Science & Commerce Stream Practice Paper Suggestions with Past years old exam Solved Question Bank for all Regional Students of English Medium, Hindi Medium & Urdu Medium Studying in KVS Schools across the Country. All the Kendriya Vidyalaya Sangathan Board Students can download the Sample Paper Suggestions with Model Papers along with Previous Years old Exam Solved Question Bank for all Languages & Subjects of the Course.

civaget 说:
2023年12月11日 23:47

English-speaking 러시아마사지 therapists ensure you get the massage you desire.

civaget 说:
2023年12月14日 01:08

In today's mobile-centric world, responsive design is non-negotiable. Your website must look and function flawlessly on various devices, contributing to 구글 상위노출 success.

civaget 说:
2023年12月15日 00:00

This is a good subject to talk about. Usually when I find stuff like this I stumble it. Although this time I’m not sure if this would be best for the users. I’ll look around and find another article that may work. NBA중계

civaget 说:
2023年12月16日 20:22

홍대 룸 – where comfort and affordability go hand in hand. Highly recommended for travelers on a budget.

civaget 说:
2023年12月18日 02:59

티비위키's content variety caters to all tastes and preferences.

civaget 说:
2023年12月19日 01:36

누누티비's content recommendations are surprisingly accurate, enhancing my viewing experience.

civaget 说:
2023年12月20日 03:29

Experience the ultimate retreat at 남양주휴게텔, Namyangju's hidden treasure.

civaget 说:
2023年12月21日 21:46 스포츠중계 has revolutionized my sports-watching experience.
civaget 说:
2023年12月26日 22:04

I have been exploring for a bit for any high quality articles or blog posts in this kind of space . Exploring in Yahoo I ultimately stumbled upon this web site. Studying this information So i am glad to show that I have a very excellent uncanny feeling I discovered just what I needed. I such a lot unquestionably will make sure to do not disregard this website and give it a look regularly. 에볼루션카지노

civaget 说:
2023年12月27日 04:37

Authors can leverage self-publishing to create book-related merchandise, such as posters and bookmarks. self publishing on amazon

civaget 说:
2023年12月30日 15:08

Good article , I am going to spend more time learning about this topic Divine Revelations


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter