Wget Command
What is Wget?
Wget is a simple Linux/Unix command-line utility for downloading the contents, files from the web. Wget will download the resource from the URL which is specified in the command. With the help of wget, we can download files using HTTP, HTTPS. We can also download multiple files, resume downloads, recursive downloads, downloads in the background, and different options in the wget command.
In this article, let’s see how to install and, use this command with examples.
Installing Wget
The wget is pre-installed on most of the Linux distros.
To verify whether the package is installed, open your terminal type wget
and press enter. You will get a result of wget: missing URL
. If the wget package is not installed it will print wget command not found.
get installation on Ubuntu and Debian
sudo apt install wget
Wget installation on macOS
brew install wget
Syntax:
wget <OPTION> <URL>
Download a File/Files with wget
Without specifying an option
wget will download the files specified in the URL to the current directory.
In the following example, we download the sample file.
wget https://file-examples.com/index.php/sample-documents-download/sample-doc-download/#
The index.html file is downloaded in the home directory.
Hide an Output
To hide an output in the terminal use the -q
option.
wget -q https://file-examples.com/index.php/sample-documents-download/sample-doc-download/#
Once the download is complete you can find the file in your current directory.
Downloading a file in a specific directory
To save the file in a specific location, use the -P
option.
Syntax:
wget -P <PATH> <URL>
Example
wget -P /home/aravind/Downloads https://file-examples.com/index.php/sample-documents-download/sample-doc-download/#
The file is downloaded in my Download directory.
Download in Background
Use -b
option to download in the background.
wget -b /home/aravind/Downloads https://file-examples.com/index.php/sample-documents-download/sample-doc-download/#
Check the wget-log
file in the current directory where the output is redirected.
To check the log, use the tail
command
tail wget-log
Downloading Multiple files
To download multiple files at once,
Create a file that contains a list of the URLs to be downloaded. Each URL is separated by a line. Use -i
option followed by the path of the links file.
The file sample-links.txt
contains four different links
https://file-examples-com.github.io/uploads/2017/02/file-sample_500kB.dochttps://file-examples.com/index.php/sample-audio-files/sample-ogg-download/https://file-examples.com/index.php/sample-images-download/sample-jpg-download/https://file-examples.com/index.php/sample-video-files/sample-mp4-files/
Command:
wget -i sample-links.txt
The downloaded files are stored in my current directory.
So, here we came to an end these are the top options used for wget.
Thanks for reading 😀😀