What is wget command?
This command is used for downloading files from internet server which are using HTTP, HTTPS and FTP protocol. wget is an non interactive program that is it can be run in background. Also with wget one can download single file, download multiple files, download background, resume downloads, limiting the bandwidth used for downloads. Also it can be used for mirroring of a website.
Examples of wget command use in Linux
Single file download with wget
Use wget with location of file to download for downloading a single file.
wget http://location_of_ file
The output of wget command displays name of file, a progress bar for download, size of file downloaded, download speed and estimated time for download to complete.
Download without standard wget output
Use quiet mode (–q switch) to download without output.
wget –q http://location_of_ file
No output will come when using wget in quiet mode
The default output of wget command is verbose. To turn it it off a no verbose switch (-nv) is provided.
wget -nv http://location_of_ file
When using –nv option basic information and error will still come up.
Change the name of file downloaded file
Using –O switch will change the name of file downloaded to new name provided by user.
wget –O test.txt http://location_of_ file/testfile.txt
To resume download use –c switch. This option should be used if a previous download of a file failed due to network drop. This option will work only if local file of previous download is still in the folder. The download will start from point where previous download was broken.
wget –c http://location_of_ file/testfile.txt
If –c switch is not used and wget command finds file with same name in folder, it will append .1 to name of file. Also if .1 name exists it append .2 to file name and so on.
Multiple files download can be downloaded by two method
By providing names of files – In this method location of all files are provided.
Download multiple files
using only http protocol
wget http://location_of_ file http://location_of_ file2
using http and ftp protocol
wget http://location_of_ file ftp://location_of_ file2
A mix of protocol (ftp, http and https) can be done while downloading multiple files with wget.
By providing names of files in a list – To download a large number of files simply use wget with switch –i and provide list of files in text file.
wget –i /test/text.txt
Above syntax utilizes wget –i switch and list of file is provided in text.txt file.
Restrict usage of Bandwidth while using wget command
If you want to restrict wget from completely utilization of bandwidth, use switch –limit-rate
wget –limit-rate=64k http://location_of_ file
This command will restrict speed of download to 64kbps.
Logging of output of wget command
To output wget command information to log file –o switch is used.
wget -o /location/of/logfile http://location_of_ file
Use wget in background
Using -b option download can be send background once download starts. If logs are not directed to any files using –o option, logs will be written to wget-log.
wget –b http://location_of_ file
Download from an untrusted location / without valid certificate
When downloading files from websites , you may encounter error regarding certificate verification. In such case use –no-check-certificate switch for wget command. Before using this option ensure about authenticity of web site. Malicious sites may infect your system.
wget http://location_of_ file --no-check-certificate
Mirror a website with wget command in Linux
To mirror a complete website –m switch can be used.
wget -m http://location_of_ file
Download secured file requiring username and password with wget command
wget can download files even from secured website. For getting through security of website you can provide username with switch –-user and password with switch –password.
wget –user=username –password=password http://location_of_ file