Using wget


wget is a utility that will allow you to fetch items from a server placed on the Internet. It is a useful utility for scripting download actions and is often used in many of our tutorials for downloading code. It is included in most distributions by default.

To download a file with wget just type the following:

# wget [options] http://www.address.com/

There are a number of options that could be appended to the command in the [options] section. Replace the http://www.address.com/ with the location you'd like to download from.

Here is an example that shows downloading the HTML source code for http://www.yahoo.com/.

# wget http://www.yahoo.com
--09:49:37--  http://www.yahoo.com/
           => `index.html'
Resolving www.yahoo.com... 69.147.76.15
Connecting to www.yahoo.com|69.147.76.15|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9,490 (9.3K) [text/html]

100%[====================================>] 9,490         --.--K/s             

09:49:38 (837.86 KB/s) - `index.html' saved [9490/9490]

 

I'll break down each one of these lines to explain their purpose.

 

# wget http://www.yahoo.com

We are requesting to download http://www.yahoo.com

 

--09:49:37--  http://www.yahoo.com/
           => `index.html

wget has went to that location and was forwarded to the index.html page. This is the page it will download.

 

Resolving www.yahoo.com... 69.147.76.15
Connecting to www.yahoo.com|69.147.76.15|:80... connected.
HTTP request sent, awaiting response... 200 OK

These are the DNS resolution and connection lines. An HTTP 200 message on the third line shows that it successfully connected to the server. If you were to get a 404 message there that would signify the file does not exist.

 

Length: 9,490 (9.3K) [text/html]

100%[====================================>] 9,490         --.--K/s             

09:49:38 (837.86 KB/s) - `index.html' saved [9490/9490]

This is the file length and the download progress.

Now if you were to look in the current directory using ls you would see the index.html file there.

# ls -l index.html
-rw-r--r-- 1 user user 9490 2009-05-20 09:29 index.html

--Kelly Koehn 09:57, 20 May 2009 (CDT)



Was this content helpful?




© 2014 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER