Table of Contents
- Install Wget Utility
- Basic Syntax for Wget
- Wget Command Examples
- 1. How to Download a File using wget
- 2. Download and Save the file with a different name.
- 3. Download multiple files using wget command
- 4. Download a File to a Specific Directory using the wget command
- 5. Download file with FTP protocol using Wget command
- 6. Download multiple files by reading URL’s from TEXT file using Wget command
- 7. Resume uncompleted downloads using wget command.
- 8. Download file in the background using Wget command
- 9. Limit speed when downloading file using Wget command
- 10. Create Mirror of Website using Wget command
- 11. Change User Agent of Wget
11 Wget Command Examples in Linux
Wget is a command line utility used for downloading files in Linux. Wget is a freely available utility and licensed under GNU GPL License. By using
wget utility you can download files with FPT, HTTP, HTTPS protocols. Wget command is also used to download the whole website using mirror feature. You can also use this command in a cron job to download files. In this tutorial, you are going to learn 11
wget command examples in Linux.
Install Wget Utility
In today’s Linux distros wget command is preinstalled. So to check whether this command is installed not run below command.
If it wget is installed you will get the following output:
wget: missing URL Usage: wget [OPTION]... [URL]... Try `wget --help' for more options.
If you don’t get above output, you can install
wget command using the following commands.
Install wget command in Debian or Ubuntu
Run below command to install
wget command in Ubuntu or any Debian based distro.
sudo apt install wget
Install wget command in CentOS or Fedora
Run below command to install
wget command in CentOS or Fedora.
sudo yum install wget
Basic Syntax for Wget
Following is the basic syntax for
wget [OPTIONS] [URL]
OPTIONS – The different options for
wget are here.
URL – The URL of the file to download.
Wget Command Examples
1. How to Download a File using wget
To download a single file you can use
wget command without any option providing only the URL of the file.
In below example it will download the Ubuntu ISO file using
2. Download and Save the file with a different name.
If you want to download the file and save with another name then you can provide the name of the file with the option
The following command will download the file and will save the file with a name
ubuntu1804.iso which provided with the option
wget -O ubuntu1804.iso http://ubuntu.biz.net.id/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
3. Download multiple files using wget command
To download multiple files you can specify multiple url’s of files. Wget will download files one by one.
In the following example
wget command will download multiple files:
wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz http://ubuntu.biz.net.id/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
4. Download a File to a Specific Directory using the
To save downloaded file in a specific directory you can use
-P option. Just provide the directory name with
The following command will download the Ubuntu ISO file inside the
wget -P /tmp/iso http://ubuntu.biz.net.id/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
5. Download file with FTP protocol using Wget command
To download the password protected file with FTP protocol you should provide FTP USERNAME and FTP PASSWORD using options
Following is an example for downloading FTP file with
wget --ftp-user=FTP_USERNAME --ftp-password=FTP_PASSWORD ftp://ftp.example.com/testfile.txt
6. Download multiple files by reading URL’s from TEXT file using Wget command
You can download multiple files using
wget command by storing multiple urls in a text file. Here you should use
-i option and URL’s inside file must be separated by newline means each URL should be on a newline.
Below is an example for downloading multiple files by reading TEXT file using wget command:
wget -i linux-apps.txt
The example file
7. Resume uncompleted downloads using wget command.
To resume the uncompleted downloads you can use
-c option with
wget command. It will start downloading the file from the point where it was stopped.
Below is an example to resume the uncompleted download.
wget -c http://ubuntu.biz.net.id/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
8. Download file in the background using Wget command
By using the
-b option you start downloading in the background. You can see related logs inside the file
wget -b http://ubuntu.biz.net.id/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
To check the status of download you can use the following command:
tail -f wget-log
9. Limit speed when downloading file using Wget command
When downloading the file if in case you want to restrict the speed limit then you can do so by using option
--limit-rate with wget command.
wget --limit-rate=500k http://ubuntu.biz.net.id/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
10. Create Mirror of Website using Wget command
You can create a mirror of the website using
wget command with
Following is an example to create a mirror of the website:
wget -m https://example.com
To browse downloaded files locally you should use some more options:
wget -m -k -p https://example.com
11. Change User Agent of Wget
Sometimes download is blocked if you are using wget agent. So to customize the user agent name you can use
wget --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" http://wget-forbidden.com/
You have successfully learned 11 Wget command examples in Linux. If you have any queries please don’t forget to comment below.