Wget for Beginners : How to use wget in Linux/Unix Based Systems

Wget is a command-line downloader for Linux and UNIX environments. It is very powerful and versatile tool used for retrieves content from web servers and websites. Wget is freely available package and license is under GNU GPL License. With wget we can download files or even entire website. It supports the download protocols (HTTP, HTTPS, FTP and, FTPS).  It helps users to download huge chunks of data, multiple files and to do recursive downloads. Main feature of Wget of it’s robustness, and it also works well in slow or unstable network connections. Some of the features of wget are resuming of downloads, bandwidth control, authentication handling etc.

Now here lets see some basic examples of how to use wget command :

first check that the wget is installed or not on your system :
 $ which wget 
if wget is installed on your system then it will return the PATH of wget /usr/bin/wget. or if it not installed then nothing will return. now to install wget use the below command
 $ sudo apt-get update
 $ sudo apt-get install wget
1. Download a file

To download a file from internet use the below command
 $ wget [url]
example :
 $ wget http://www.mysongs.com/playlist/song.mp3
2. Downloading multiple files with different Protocols and Urls :

To download multiple files with different protocol use the below command
 $ wget http://sourceforge.net/Source/wine/wine-3.0.tar.xz ftp://gnu.org/unrar/unrar2.5.tar.xz
3. Download and save file with different name : 

To download the file and after that save it with different number :
 $ wget -o [file_name] [url]
example :
 $ wget -o track1.mp3 http://www.mysongs.com/playlist/song.mp3
4. Using an input file downloads file in bulk :

We can also use an input file to download files in bulk. We need top put all the links in that file and then with this we can download all the file in bulk.
 $ wget -i [filename_with_full_path]
example :
 $ wget -i /home/user/list.tst
5. Resume incomplete download :

Sometimes a download is interrupted in the middle due to some reason. We can resume a partial download in wget by using -c option :
 $ wget -c http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-i386.iso
But when you try to resume any download then make sure that the previously partial downloaded file's name is same as the name of file in the server, otherwise it may not resume.

6. Download file in background 

When we are downloading a huge file, then it will take a lot of time to complete. In that situation we can download the file with wget as background process with -b option
 $ wget -b http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-i386.iso
and save the output of wget as log file, use this :
 $ wget -b /home/user/download_log.txt http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-i386.iso
7. To restrict or limit the download speed :

To restrict or limit the download speed 
 $ wget --limit-rate=50k 
At here the maximum download speed is 50 Kbps. for example :
 $ wget -limit-rate=50k http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-i386.iso
8. Downloading files with authentication :

Some sites restrict access to content by requiring a username and password. In this situation we have to provide username/password.

For FTP server :
 $ wget --ftp-user=johnwick --ftp-password=killer123 [Url]
For HTTP server
 $ wget --http-user=johnwick --http-password=killer123 [Url]
9. Setting up number of Attempts : 

By default, the wget command would make up to 20 attempts to connect to the given website for completing the download in the event of unstable internet connectivity. At this situation we can also set the number of attempts by --tries option.
 $ wget --tries=[Desired_Value] [URL]
example :
 $ wget --tries=30 http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-i386.iso
10. Downloading or Mirroring a complete website :

With wget we can download or mirror a complete website in our local drive by --mirror option.
 $ wget --mirror [URL]
example :
 $ wget --mirror http://gnu.org
And at last for help type :
 $ wget --help
And for manual page type :
 $ man wget

Conclusion :

The wget utility is very powerful tool. In this post we saw some basic usage of wget command with examples. For more information about wget you can check manual page at here : https://www.gnu.org/software/wget/manual/wget.html