Signup/Sign In
PUBLISHED ON: AUGUST 2, 2021

Wget Command in Linux

Wget is a utility command in Linux that is used to download files from the web. We can use it to download files from HTTP, HTTPS, or FTP servers.

We can use this to download a website also. It provides several options that are useful to download files as per the requirement. So, let's start learning.

Download a file using wget in Linux

You can use this command to download a file from the web. You can pass the file path with the command, without any option. This is a simple command, later in the article, we will learn with flag/options.

$ wget https://www.mysite.com/filename.zip

This utility is preinstalled in all the Linux distros, but in case if not available then use these commands to download.

Installing Wget on Ubuntu and Debian

$ sudo apt install wget

Installing Wget on CentOS

If you are using CentOS operating system then use this command to download and install the wget.

$ sudo yum install wget

Installing Wget on Fedora

If you are using Fedora operating system then use this command to download and install the wget.

$ sudo dnf install wget

Wget Command Syntax

This is a general structure of the wget command in Linux.

$ wget [option] [url]

How to Download a File with wget

To download a file from the web, use wget command with the location of the file. It will store the file in the current directory of your computer.

$ wget https://www.mysite.com/filename.zip

Saving the Downloaded File with Different Name

If you want to set a new name to the downloaded file then use -o option with the wget command. Be default file is downloaded with the original name and it may cause to overwrite if any file with the same name already exists.

$ wget -O latest-hugo.zip https://github.com/gohugoio/hugo/archive/master.zip

Downloading a File to a Specific Directory

If you want to store the downloaded file in a directory other than the current directory then use -p option with the wget command. The given command

$ wget -P /mnt/iso https://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso

Limiting the Download Speed

This command provides an option to set the limit of downloading speed so that you can adjust the downloading as per the requirement. The --limit-rate option do this. You can pass the value as 1m(1 Mb), 10k(10 kb), etc.

wget --limit-rate=1m https://dl.google.com/py/g52.14.1.linux-amd64.tar.gz

Resuming a Download

Sometimes the downloading stops either due to poor network or any other reason then don't worry, you can resume it by using the -c option with the wget command. This command will ask the server to start from the point where it was stopped.

$ wget -c https://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso

Downloading in Background

If you want to put the downloading process into the background then use the -b option with the command, it will hide the process and continue in the backend.

wget -b https://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso

Downloading via FTP

Downloading from the FTP server requires a username and password along with wget command. So, provide proper valid credentials to download the files.

wget --ftp-user=FTP_USERNAME --ftp-password=FTP_PASSWORD ftp://ftp.mysite.com/filename.tar.gz

Creating a Mirror of a Website

If you want to download a copy of any website then use -m option with the command. It will download a mirror of the site to your local computer.

wget -m https://mysite.com

Conclusion

The wget is a command in Linux which is helpful to download a file from the web. It allows downloading files from HTTP, HTTPS, and FTP servers. We can use it to download files in the current directory or a different one, download in the background, and even control the speed of downloading by using a special flag with the command.



About the author:
Pradeep has expertise in Linux, Go, Nginx, Apache, CyberSecurity, AppSec and various other technical areas. He has contributed to numerous publications and websites, providing his readers with insightful and informative content.