10 Examples of wget command in Linux

Hey there! Today's article will explain the "wget" command in Linux and 10 different examples. If you are a Linux user, this is a command you will commonly use almost every now and then.

WHAT IS THE "WGET" COMMAND?

Wget emanated from the GNU project. It is a non-interactive tool used to download files from the web. It is called non-interactive because it does not need human interaction before it operates. the user does not have to log on before it works.  This means that it works in the background. Wget supports HTTP, HTTPS, FTPS,SFTP.

"wget" is very beneficial in such a way that, If you are downloading a file and unfortunately the network connection becomes unstable and slow, It keeps retrying until the file is fully recovered. 
Before you can start using "wget" command, you must have installed that on your Linux. if not It won't recognize that command if you type it.

EXAMPLES OF WGET COMMAND in Linux

1. Downloading a file from the web

Like I said earlier we are going to 10. the first example of "wget" command we are looking into is downloading it with a file.
Basically, This is done by providing the location of the file that is to be downloaded over an HTTP.
 
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz
With the above command, file.zip is going to be downloaded into the current working directory. Well, you could download any different kind of extension depending on what kind of file you are downloading. The result is:
10 Examples of wget command in Linux


You can see that the download has started  and it will go all the way to 100 percent

2. You could as well download a file in the background

wget -b wget.log https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso

The difference between the first and the second is the -b indicator, This indicates that this should happen in the background. Then in the output, we have:


3. To download a file with a different name

With the option -O, files are downloaded with different file names, below is the option and the result. Note that, the "O" option is in uppercase.

 wget -O wget.zip http://ftp.gnu.org/gnu/wget/wget2-2.0.0.tar.gz


4. To resume a file that was partially downloaded.

wget -c https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso
There could be instances whereby your file did not fully download due to many possible reasons e.g poor network connection. If the file has been downloading,it stops at the point the internet went bad. In that case it would partially download, the use of the command helps in resuming the partially downloaded file.

This is at 3% , still loading when i took the image. When it gets to 100% then it's done

5. To set the number of retry.

wget -tries=100 https://wordpress.org/latest.zip
The syntax here helps you set how many number of times you want to retry. The default number of try is 20. But when a very fatal error occurs like, if the connection refuses, or link is not found, it closes down and it does not retry again.


6. To find help

wget --help
The syntax helps with the necessary information, This is going to print a help message by displaying all the possible information about the command. and if you like you may include a URL but it is not compulsory. It only depends on whatever you are trying to do.



7. To log messages on a file

wget -o logfile [url] 
This is used when you need to log the messages from the system to a file. You must have specified a file, so when it is done executing it transfers the messages in the log file. But if no file option was specified, then the default log file is being used. All messages will find their way to the default log file


8. To download file from an untrusted or unsecured URL

wget --no-check-certificate https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.1.1.tar.gz
This command enables you to download file from an untrusted or unsecured url, the option check no certificate forces the download to happen without checking the validity of the certificate. so therefore the certificate validity checking is ignored.

9. To get the version of wget

To get the version of the wget you are using, simply do 
  wget --version


10. To Limit the download speed while downloading a file.

wget -c --limit-rate=100k -b wget.log https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso
The command above sets the download speed rate


CONCLUSION

In this article, you learnt how to 10 different ways in which you can use wget command in linux which are: Downloading file from a web, downloading from a background, to get a version you are using, to resume a partially downloaded file, to set the number of retry,to find help, to log messages on the file, to download from an untrusted url, to overwrite an existing file and to limit the download speed while downloading a file. With these understanding you can start using the commands. "wget" command in linux is not limited to 10, we only covered 10 examples here and I hope this helps, Thank you!

No comments:

Post a Comment

Feel free to comment, ask questions if you have any doubt.