×



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.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Wget queries.

In this context, we shall look into how to use wget command with example and explanations of all wget options.


How to Install Wget Utility ?

By default, 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.


How to Install wget command in Debian or Ubuntu ?

Execute below command to install wget on Debian or Ubuntu operating system:

$ sudo apt install wget


How to Install wget command in CentOS or Fedora ?

Run the following to install wget on your CentOS or Fedora system:

$ sudo yum install wget


What is 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

1. 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


2. To 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


3. To 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/linuxapt http://releases.ubuntu.com/18.04/ubuntu-18.04.2-desktop-amd64.iso

In above command the downloaded file will be stored at /home/linuapt directory.


4. To 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.


5. 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


6. To 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


7. 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


8. To 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


How to use 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


How to 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/


How to 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

Where 'domain-with-invalid-ss.com' should be replaced by your domain.


[Need to perform Software Installation tasks with wget command? Let us Know. ]


Conclusion


More Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on IbmiMedia.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com