wget – Download using the command line

Filed in Linux

There are many ways to download the files from the sources, it can be done by right clicking on the link and choosing to save the given file, but that may take long time and tiring.

If you are on Linux distro then you can use a better approach to use wget command line.

It is usually installed in all Linux distros, but if not we can install it.


Debian / Ubuntu

apt-get install wget

Fedora / CentOS

yum install wget

Check out the some of the features below.

If there is the need to download a single page.

wget http://www.sourcewebsite.com/file.pdf


wget http://www.sourcewebsite.com/music.mp3

But if there is the need to download the entire site, use the recursive option.

wget -r http://www.sourcewebsite.com

Now what to do if only certain file types are needed? Use the -A option

To download only pdf and jpg use.

wget -r -A pdf,jpg http://www.sourcewebsite.com

Well now suppose that there is the need to follow external links, usually wget does not do this, here we can use -H option.

wget -r -H -A pdf,jpg http://www.sourcewebsite.com

This is a little bit dangerous as it could end up downloading a lot much files that the ones needed, so we could limit the sites to follow, we will use -D for this.

wget -r -H -A pdf,jpg -Dfiles.sourcewebsite.com http://www.sourcewebsite.com

By default wget will follow 5 levels when using -r option, we can change this behaviour with the -l option.

wget -r -l 2 http://www.sourcewebsite.com

This way only two levels depth will be followed.

Leave a Reply

Your email address will not be published. Required fields are marked *