Wget is a command line utility in linux to download files from the internet. It provides many features such as downloading multiple files, resuming stopped downloads, limiting the bandwidth, downloading in the background and can be used for taking mirrors of the site. Wget supports HTTP, HTTPS and FTP protocol to connect server and download files. In this article , we are going to learn wget commands with 15 quick examples.
1) Downloading single file with wget
To download a single file using wget command, type wget and absolute path of the file.
$ wget https://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso
This command will download Ubuntu 20.04 desktop iso file
2) Download files in the background
Wget utility can be used to download the files in background. To activate background download , run wget command with -b option
$ wget -b https://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso
This command will download Ubuntu 20.04 desktop ISO file in background.
You can find the download logs using the following command.
$ tail -f wget-log
You will find following output in your terminal
3) Wget command to resume partially downloaded file
In case your download is terminated by some reason and you have got your file partially downloaded , you can resume the download again. Execute the wget command followed by -c option to resume your download .In this example I have used the following command to resume my Ubuntu 20.04 desktop iso download..
$ wget -c https://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso
This command will resume your downloads
4) Download Multiple files with wget command
You can use wget command to download multiple files in a single command. To download multiple files, you can put download urls to the text file and execute wget command followed by -i option with download urls file.
$ wget -i lists.txt
In this example I have included multiple download urls in the text file and executed wget command to download multiple files.
5) Wget command to limit download speed
Full bandwidth is consumed by wget while downloading the files from the internet. Sometimes you may need to limit your download speed. Using wget you can limit your download speed with option –limit-rate= your limit rate. In this example I have used bandwidth limit to download files.
$ wget --limit-rate=200k https://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso
This command will download Ubuntu iso from the internet with a speed of 200kb per second.
6) Wget command to exclude files types while downloading
Sometimes you may want to exclude certain file types while downloading files. You can use the “reject” option followed by file types which you want to exclude from downloads.
$ wget --reject=png ubuntu.com/download
This command will download all the files available in the url except png files.
7) Wget command to set download quota
You can set download quota while downloading files using wget command. Use wget command with option -Q to set quota in your downloads.
$ wget -Q20m -i downloads.txt
For single download the quota limit will not be applied. Your downloads will be aborted only when you download files recursively or from an input file.
8) Wget command to download files without SSL certificate check
Sometimes the site you are trying to access and download files might have expired SSL certificate and your download may not be successful. Wget utility allows you to download files without checking SSL certificate of the site. You can use wget command with option –no-check-certificate.
$ wget ubuntu.com/download --no-check-certificate
9) Wget command to download retry attempts
Downloads getting failure and not retrying again may be horrible when you want to download important files. In the wget command line you can apply download retry attempts with option “–tries” option.
$ wget --tries=10 https://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso
This command will try 10 times to download the Ubuntu iso file in case of download failure.
10) Wget command to redirect wget logs to log file
You can redirect wget logs to a specific log file using “-o” option.
$ wget -o downloads.log https://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso
This command will create a log file download.log while downloading Ubuntu ISO file.
11) Wget command to download files and extract in single command
You can use wget to download files and extract in a specific directory. In this example I am going to download wordpress latest tar file and extract it in the directory /var/www/html.
$ sudo wget -q -O - http://wordpress.org/latest.tar.gz | tar -xzf - --strip-components=1 -C /var/www/html
12) Wget command to download files from password protected sites
You can pass username and password with wget command to download files from password protected sites. It works on both http and ftp protocol with option “–http-user” “https-password” “ftp-user” “ftp-password” . You can pass username and password with wget command to both http and ftp site as:
$ wget --http-user=user --http-password=password http://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso $ wget --ftp-user=user --ftp-password=password ftp://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso
13) Wget command to view server response
Wget command can also be used to view HTTP headers sent by server or response sent by ftp server using “-S” option.
$ wget -S http://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso
This command will print HTTP response sent by server in your terminal as:
14) Wget command to Abort download if it takes too long
You can use the “-T” option followed by the number of seconds to cancel the download automatically after specified timeout.
$ wget -T 40 http://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso
In this example. Your download will automatically be aborted if the the data is not retrieved within 40 second.
15) Wget command with wait time
Usually wget command performs retry straight away, however we can delay next retry time with using “-w” option followed by a number of seconds. It is useful if the server is slow or unresponsive.
$ wget -w 10 -i downloads.txt
This command will wait for 10 sec to perform another download mentioned in the downloads.txt file.
In this article you have learned different uses of wget command line utility. Please don’t hesitate to share your feedback and comments.
Also Read : Learn IP Command to Manage Networking on Linux