How To Use Wget Command in Linux

In this guide, we intend to teach you How To Use Wget Command in Linux.

The wget command is a command line utility for downloading files from the Internet. It supports downloading multiple files, downloading in the background, resuming downloads, and limiting the bandwidth used for downloads and viewing headers.

Also, it can be used for taking a mirror of a site and can be combined with other UNIX tools to find out things like broken links on a site.

Use Wget Command in Linux

This guide will show you how to use the wget command with the most useful commands and options examples.

The wget package is pre-installed on most Linux distributions today.

To check whether the Wget package is installed on your system, open up your console, type wget, and press enter. If you have wget installed, the system will print wget: missing URL. Otherwise, it will print the wget command not found.

If you don’t have the wget command on your Linux distro, you can easily install it on your server with the Linux Commands.

Install Wget on Debian / Ubuntu

sudo apt install wget

Install Wget on Centos / Fedora / RHEL

sudo yum install wget

General Syntax of Wget Command

At this point, we want to show you the basic syntax of the wget command. It looks like this:

wget [OPTION]… [URL]…

Now proceed to the next step to see how to use it on your Linux system.

Download a File with Wget Command in Linux

When you use the wget command without any options, it will download the resource specified in the [url] to the current directory.

For example:

wget http://example.com/sample.php

You can save your file under a different name by using the “-O” option. For example:

wget -O latest.php http://example.com/sample.php

This command will save the file with the name of the latest.php instead of the original name.

By default, wget will save the downloaded file in the current working directory. To save the file to a specific location, use the “-P” option in the wget command in Linux. For example:

wget -P /opt/download http://example.com/sample.php

Limit Download Speed with the Wget Command

By default, the speed is measured in bytes/second. You can easily limit your download speed by using of the “–limit-rate” option. For example:

wget --limit-rate=1m http://example.com/sample.php

This will limit the download speed to 1MB.

You can use k for kilobytes, m for megabytes, and g for gigabytes.

Note: This option is useful when you don’t want wget to consume all the available bandwidth.

Resume Downloading process with Wget Command

If your connection drops during downloading a file, you can resume your downloading by using the “-c” option. For example:

wget -c http://example.com/sample.php

Note: If the remote server does not support resuming downloads, wget will start the download from the beginning and overwrite the existing file.

Download a File in the background with the Wget Command

If you plan to download a file in the background, you can use the wget command in Linux by using the “-b” option. For example:

wget -b http://example.com/sample.php

By default, the output is redirected to the wget-log file in the current directory. To watch the status of the download, you can use the tail command:

tail -f wget-log

Download Multiple Files with the Wget Command

Here you can use the “-i” option in the wget command to download multiple files at once.

The “-i” option is used to read URLs from the file. If -i is specified as a file, URLs are read from the standard input. And if this function is used, no URLs need to be present on the command line. If there are URLs both on the command line and in an input file, those on the command lines will be the first ones to be retrieved. The file need not be an HTML document if the URLs are just listed sequentially.

$ wget -i inputfile
$ wget -i inputfile [URL]

Download a File to a Standard Output

In the following example, wget will quietly ( flag -q) download and output the latest WordPress version to stdout ( flag -O –) and pipe it to the tar utility, which will extract the archive to the /var/www directory.

wget -q -O - "http://wordpress.org/latest.tar.gz" | tar -xzf - -C /var/www

For more help, you can use the following command:

wget --help

Conclusion

At this point, you learn to Use Wget Command in Linux with the most widely used options.

Hope you enjoy it.

You may be interested in these articles:

How To Work with the Dig Command on Linux

Cron in Linux

Environment Variables in Linux

How To Troubleshoot DNS in Linux

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular