How to Install and Use Wget Command in Linux

In this tutorial , you will learn how to install and use wget command tool.GNU Wget is a command-line utility for downloading files from the web. it provides a number of options allowing you to download multiple files.

Step 1. Installing Wget

To install wget on Debian/Ubuntu/LinuxMint distros.

sudo apt install wget

To install wget on Fedora/CentOS/RHEL distros.

sudo yum install wget

To install wget on OpenSUSE distro.

sudo zypper install wget

To install wget on archLinux/Manjaro distros.

sudo pacman -Sy wget

Step 2. Download files use wget command

To know more about wget usage and examples, you can read the following examples.

1. Single file download

The command will download single file and stores in a current directory.

wget http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz

During the download, wget shows the progress bar alongside the file name, file size, download speed, and the estimated time to complete the download.

2. Download file with different name to Saving

Using -O (uppercase) option, downloads file with different file name. Here we have given wget.zip file name as show below.

wget -O wget.zip http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz

3. Downloading a File to a Specific Directory

Using -P (uppercase) option, To save the file to a specific location:

wget -P /opt/download/ http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz

4. Downloading in Background

Using -b option, To download in the background:

wget -b http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz

The output is redirected to wget-log file in the current directory.

5. Changing the Wget User-Agent

Using –user-agent option , downloading a file that the remote server may be set to block the Wget User-Agent.

wget --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz

The command above will emulate Firefox 60 requesting the page from ftp.gnu.org download wget-lasted.tar.gz file.

6. Read URL’s from a file to Downloading Multiple Files

With -i option, You can store number of URL’s in text file and download them . for the following example:

wget -i /opt/wget/urls.txt

7. Restrict download speed limits

With Option –limit-rate=100k, the download speed limit is restricted to 100k and the logs will be created under /opt/wget/log.txt as shown below.

wget -c --limit-rate=100k /opt/wget/log.txt http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz

8. Downloads with username and password from a password-protected FTP server

To download a file from a password-protected FTP server, specify the username and password as shown below:

wget --ftp-user=FTP_USERNAME --ftp-password=FTP_PASSWORD http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz

9. Resume uncompleted download

In case of big file download, it may happen sometime to stop download in that case we can resume download the same file where it was left off with -c option. But when you start download file without specifying -c option wget will add .1 extension at the end of file, considering as a fresh download. So, it’s good practice to add -c switch when you download big files.

wget -c http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz

10. Find wget version and help

Using Options –version and –help you can view version and help as needed.

wget --version

wget --help

Conclusion

In this tutorial, we have shown you How to Install wget command and Use it with options for daily download tasks.

Try now!

Leave a Reply