How to Install ERPNext on Rocky Linux 9 3

How to Use wget Command in Linux

With the help of the wget command in Linux, you can seamlessly download multiple files and even rename them in real-time. The command-lite utility also helps in resuming partial downloads and mirroring desired websites with ease.

For those who are after downloading files employing HTTP, HTTPS, and even FTP protocols, wget is a promising utility. It can better be defined as a command-line utility that lets Unix-based users download files from remote servers in whatever way they want.

From limiting the downloading speed to resuming interrupted downloads, from renaming files to letting the download continue in the background, the wget command in Linux offers complete downloading freedom most flexibly.

Installing wget in Linux

Before you start using the wget command in Linux, it is pretty obvious for you to have all the wget utilities installed on your system. Although most of the Linux distributions these days already have the wget package pre-installed, it is always a better idea to verify.

Checking whether your system has a wget package installed on not is simple. Launch the Terminal using the “Ctrl+Alt+T” key combination and run the wget command.

The system with pre-installed wget packages will print:

wget: missing URL
verifying wget command in Linux

In other cases, you’ll come across a wget command not found message.

If you come across the not found message, there is nothing much to worry about. You can effortlessly install wget packages by running a simple command. However, to conclude the process, you must have all the sudo privileges.

Installing wget on Ubuntu and Debian

Run the following command:

$ sudo apt install wget
installing wget command

Installing wget on CentOS and Fedora

Run the following command:

$ sudo yum install wget

wget Command in Linux: Syntax

wget command in Linux has a pretty basic and straightforward syntax that looks something like this:

wget [options] [url]

The [url] signifies the URL of the file or the desired directory that you wish to synchronize or download.

Using wget Command in Linux

Now that you know how to install the wget package on your system and are aware of the basic syntax, let’s walk through the usages in detail.

Downloading File with wget Command in Linux

When the wget command in Linux is used without any option, it will simply instruct the system to download the resource which the provided [url] specifies. In other words, launch the Terminal and run the wget command followed by the URL to download the derided file.

For Example, running the following command will download the Linux kernel tar archive.

$ wget [URL]
downloading file with wget command

From the image, you can clearly understand the working mechanism of the wget command in Linux while downloading a file. It starts off resolving the specified domain’s IP address. It then connects to the server to eventually start the downloading process.

As the system downloads the file, it will display some additional information alongside the name. This includes size, speed, and the estimated time as well. In case you don’t want your system to display this form of output, you can simply use the -q flag.

For any duplicate download, the wget command will add a number to signify the number of repetitions.

Another vital thing to take care of is that if you want to download a file from a host with an invalid SSL, inputting the —no-check-certificate is crucial. This will simply let your system skip the certificate check.

For Example:

$ wget --no-check-certificate [url]
no certificate check wget command in Linux

Using wget Command in Linux to Download and Save a File in Different Name

There may be situations when you need to download a file and assign a different name while saving it. Well, using the -0 option together with the wget command followed by the desired name will do that.

For Example: 

$ wget-0 New Tar  [URL]
changing name of downloaded file using wget command

Running the command as mentioned above will save the kernel tar archive as New Tar instead of the original name.

Limiting the Download Speed with wget Command in Linux

Don’t want the wget command to consume all the available network bandwidth? Here is the easy way out.

Employing the --limit-rate flag alongside the wget command will help you limit the download speed for any file. But make sure to define the value. In general, the download speed is measured in terms of bytes per second; however, you can also append different units.

Considering, you want to limit the download speed to certain megabytes. In that situation, use the m flag. The same for kilobytes and gigabytes are k and g, respectively.

For example: 

$ wget --limit-rate=2m [url]
limit downloading speed

This will limit the download speed to 2 megabytes.

Use wget Command in Linux to Download a File to Specific Directory

Talking about the default scenario, the wget command in Linux saves the downloaded file on the directory you’re currently working on. To use a different location instead, use the -P flag followed by the desired directory.

For Example:

$ wget -P desired directory [url]

wget Command for Downloading via FTP

If you’re downloading a file from a password-protected source or FTP serve, it is essential to input the username and the password together with the wget command. Use the following sequence to specify and download such types of files.

$ wget --ftp-user=FTP_USERNAME --ftp-password=FTP_PASSWORD [url]
wget command for password protected downloads

Resuming a Download Using wget Command

A sudden drop in connection can be hectic, especially while downloading a large file. Luckily you can use the -c flag and resume the download process instead of starting everything from scratch.

For Example:

$ wget -c [url]

It is important to keep in mind that if the server you’re downloading from doesn’t support the resume capability, the command will simply download the file from the beginning overwriting the existing file.

resuming downloads in Linux

wget Command in Linux for Downloading in Background

Using the -b flag with the wget command in Linux will instruct the system to download the file in the background.

For Example:

$ wget -b [url]
download file in the background

Downloading Multiple Files with wget Command

In case you’re wondering if downloading multiple files with the wget command is a genuine possibility or not, the answer is yes. Use the -i flag together with the wget command followed by the path and the list of URLs from where the files are to be downloaded.

Save a file containing all the URLs. Suppose, Linux-Kernels.txt

Run the following command:

$ wget -i Linux-Kernels.txt
downloading files from multiple url

Creating Website Mirror with wget Command in Linux

Creating a website mirror with the wget command is simple. Run the command alongside the -m flag, and this will download all the links and other resources.

However, to make the downloaded mirror capable for local browsing, use -k and -p options. While -k converts the links in the downloaded documents, -p flag instructs wget to download the necessary files for local browsing.

For Example:

$ wget -m -k -p [url]

Using wget Command in Linux to Download to the Standard Output

Do you want to download to the standard output? Use the -q -0 - flag. For instance, the following command will download the latest version of Linux Kernel to the standard output. This will further pipe the file to tar utility and extract the same to /var/www directory.

$ wget -q -0 -  [URL] | tar -xzf - - C /var/www
wget command in Linux for standard output

What if  the Wget User- Agent is Blocked

There are several remote servers that tend to block the wget user-agent. An attempt to download files from those servers with the wget command will not help in any manner. Luckily, there is a simple way out.

Passing the -U flag will help your system emulate a different browser.

This is almost everything that you need to know about the wget command in Linux. This post comprehensively talks about how to use the wget command and download files from remote servers with ease.

If this guide helped you, please share it.

Leave a Reply
Previous Article
How to Install ERPNext on Rocky Linux 9 4

How to Use chown Command in Linux

Next Article
How to Install ERPNext on Rocky Linux 9 5

How to Use netstat Command in Linux

Related Posts