wget command in Linux is basically a utility that is used for downloading files from a web server. Using this command, the users can download various files from their chosen networks using protocols like HTTP, HTTPS, and FTP.
With the usage of wget command in Linux, user can play with different options like downloading multiple files, resuming downloads, limiting bandwidth, recursive downloads, running downloads in background, and many more. So, in this article we are to discuss how this command can be used and how a Linux user can play with downloads using command line.
Table of Contents
Syntax of wget command in Linux
wget [option] [URL]
How to install wget in system?
Although the wget package is pre-installed on most of the Linux distributions in modern era, still if you find the package is not installed on your device, you can install it manually.
In order to check if wget package is installed, just open terminal and run the command below:
In case if running the command shows wget:missing URL, it means the package is already installed. Otherwise, wget command not found, will be displayed.
Install wget on Ubuntu/Debian systems
sudo apt install wget
Install wget on CentOS/Fedora
sudo yum install wget
Options available to use with wget:
- -v | –version: Displays version of wget package.
- -h | –help: Displays help instructions on screen with all possible options.
- -o logfile | –output-file=logfile: Used for directing all messages to a specified log file. If the file is not specified, the logs are stored on default log file. The messages are generally reported to standard error.
- -b | –background: Using this option, the download process is sent to run in background as soon as the process starts. In case if no file is specified using -o, the output is directed to wget-log by default.
- -a: Used for appending log file. This option is probably similar to -o, however it appends just the logfile instead of overwriting the old log file. In case if there’s no log file exist, a new file is created.
- -i: Used to specify a file from which wget reads the URL.
- -t number | -tries=number: Used to set a specified number of tries. 0 or inf can be specified to retry at infinity. The default number of retry is 20 times.
- -c: Used for resuming a partially downloaded file if the resume capability of file is yes.
- -w: This option is used to set the system to wait for the specified number of seconds between retrieving the next data packet. With the help of this, the server load can be lightened as it use to make requests less frequently.
- -r: This option is technically a recursive call to a specified link in command line. Using this, it keeps recursively retrieving the link specified, even in case of fatal errors.
Examples of wget comand in Linux
1: Download a specified file
sudo wget https://servonode.com/sample.pdf
2: Downloading a file in background
sudo wget -b https://servonode.com/sample.pdf
3: Overwriting the log file
sudo wget https://servonode.com/sample.pdf -o /path/to/file.txt
4: To try downloads for 5 times only (default number of retrial is 20)
sudo wget –tries=5 https://servonode.com/sample.pdf
5: Resume a partially downloaded file
sudo wget -c https://servonode.com/sample.pdf
6: Displaying version information
sudo wget -v
7: Show wget help information
sudo wget -help
8: Limiting download speed rate
sudo wget –limit-rate=3m https://servonode.com/sample.pdf
9: Downloading multiple files at once
first create a file names url_list.txt
sudo nano url_list.txt
type multiple urls in the file which you want to download using wget. Below is just an instance
https://servonode.com/sample.pdf https://servonode.com/sample1.pdf https://servonode.com/sample2.pdf https://servonode.com/sample3.pdf https://servonode.com/sample4.pdf
Save and exit the file. Now run wget with -i option to download files from the url specified in created file.
sudo wget -i url_list.txt
10: Download file using FTP
sudo wget --ftp-user=FTP_USERNAME –ftp-password=FTP_PASSWORD ftp://ftp.example.com/filename.txt
12: Downloading a site mirror using wget
sudo wget -m https://servonode.com
Nishant Verma is a senior web developer who love to share his knowledge about Linux, SysAdmin, and more other web handlers. Currently, he loves to write as content contributor for ServoNode.