
In this tutorial, we will show you how to use wget command with example and explanations of all wget options.
What is Wget?
Wget is command line utility for downloading files in Linux from web. Using wget utility you can download files with FPT, HTTP, HTTPS protocols. It is free available utility and comes with GPL License. With use of wget command options, you can manage multiple files download, recursive downloads, limit the bandwidth, mirror a website, resume downloads, download in background and more.
Installing Wget Utility
Now a days, wget utility is pre-installed on all Linux distributions. To check either wget installed or not open your terminal, type wget
and hit Enter
key. If wget is installed then it will show output as below other will print wget command not found
.
Output
wget: missing URL
Usage: wget [OPTION]… [URL]…
Try 'wget --help' for more options.
If wget is not installed you can easily install using package manager on your distribution.
Install wget command in Debian or Ubuntu
Execute below command to install wget on Debian or Ubuntu operating system:
sudo apt install wget
Install wget command in CentOS or Fedora
Run the following to install wget on your CentOS or Fedora system:
sudo yum install wget
Wget Command Syntax
It is good practice to know basic syntax of command before using it. So following is the basic syntax for wget
command:
wget [OPTIONS] [URL]
Where,
OPTIONS – Different options for wget.
URL – URL of the file which need to download.
Wget Command Examples
How to Download a File using wget
You can download a single file using wget command without any options. It will store downloaded file to current directory. In below example it will download the Ubuntu ISO file using wget command:
wget http://releases.ubuntu.com/18.04/ubuntu-18.04.2-desktop-amd64.iso
Download and Save the File With a Different Name
If you want to download file and want to save with different name instead of original then you can provide file name along with the option -O
Below example will download the file and will store it with name Ubuntu18042.iso
to current directory.
wget -O Ubuntu18042.iso http://releases.ubuntu.com/18.04/ubuntu-18.04.2-desktop-amd64.iso
Download File to a Specific Directory
By deafult, wget command will store file to current working directory. If you want to store downloaded file to specific location you can provide directory path with -P
option.
wget -P /home/tecnstuff http://releases.ubuntu.com/18.04/ubuntu-18.04.2-desktop-amd64.iso
In above command the downloaded file will be stored at /home/tecnstuff
directory.
Download multiple files using wget command
Wget provides facility to download multiple files using single command. Specify the url multiple urls along with wget command and it will start download one by one.
In below example wget will download multiple files and store to current directory.
wget http://releases.ubuntu.com/18.04/ubuntu-18.04.2-desktop-amd64.iso http://releases.ubuntu.com/18.04/ubuntu-18.04.2-live-server-amd64.iso
If you have many url then you can make a list file and can download multiple file using below command:
wget -i files-urls.txt
Your list file will contains all the urls on each new line.
http://releases.ubuntu.com/18.04/ubuntu-18.04.2-desktop-amd64.iso
http://releases.ubuntu.com/18.04/ubuntu-18.04.2-live-server-amd64.iso
It will read download urls from file and will download one by one.
How to Limit the Download Speed with Wget
You can manage wget download speed using --limit-rate
option. You can pass value in kilobytes with k
suffix and megabytes with m
suffix.
The following command will download the file and limit the download speed to 512kb
:
wget --limit-rate=512k http://releases.ubuntu.com/18.04/ubuntu-18.04.2-desktop-amd64.iso
Download file with FTP protocol using Wget command
To download password protected file using FTP protocol you must provide username and password of along with --ftp-user
and --ftp-password
option.
Below is an example of downloading FTP file with wget command:
wget --ftp-user= --ftp-password= ftp://ftp.example.com/file.zip
How to Resume a Download with Wget
You can resume a uncompleted downloads with the use of -c
option along with wget command. It’s very useful when your connection lost during a download of a big file so instead of start download from beginning it will continue where it was stopped.
wget -c http://releases.ubuntu.com/18.04/ubuntu-18.04.2-live-server-amd64.iso
Download in Background with Wget
By using the -b option you start downloading in the background. This is useful when you are downloading large files.
wget -b http://releases.ubuntu.com/18.04/ubuntu-18.04.2-live-server-amd64.iso
The output is redirected to wget-log file in the current directory. To watch the status of the download, use the tail command:
tail -f wget-log
Using Wget Command to Create a Mirror of a Website
To create a mirror of the website using wget command with -m
option. It will follow all the internal links and download all the files including website resources files JavaScript, CSS and Images.
wget -m https://example.com
To browse downloaded files locally you should use some more options:
wget -m -k -p https://example.com
Change the Wget User-Agent of Wget
Sometimes when downloading a file, the remote server may be set to block the Wget User-Agent. At this time you can customize the user agent name using --user-agent
option:
wget --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" http://wget-forbidden.com/
Skip Certificate Check with Wget Command
If your downloading file over HTTPS from a host that has an invalid SSL certificate then use the --no-check-certificate
flag:
wget --no-check-certificate https://domain-with-invalid-ss.com
Conclusion
You learned multiple wget command for different operations along with options. You can learn more about Wget visit the GNU wget Manual page.
Leave a Reply