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.
Use of wget command
Single file download with wget
Use wget with location of file to download for downloading a single file.
Syntax
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.Syntax
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.Syntax
wget -nv http://location_of_ file
When using –nv option basic information and error will still come up.
- Use quiet mode (–q switch) to download without output.Syntax
Change the name of file downloaded file
Using –O switch will change the name of file downloaded to new name provided by user.
Syntax
wget –O test.txt http://location_of_ file/testfile.txt
Resume download
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.
Syntax
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.Syntax
using only http protocolwget 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.Syntax
wget –i /test/text.txt
Above syntax utilizes wget –i switch and list of file is provided in text.txt file.
- By providing names of files – In this method location of all files are provided.Syntax
Download multiple files
If you want to restrict wget from completely utilization of bandwidth, use switch –limit-rate
Syntax
wget –limit-rate=64k http://location_of_ file
This command will restrict speed of download to 64kbps.
Logging of output
To output wget command information to log file –o switch is used.
Syntax
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.
Syntax
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.
Syntax
wget http://location_of_ file --no-check-certificate
Mirror a website
To mirror a complete website –m switch can be used
Syntax
wget -m http://location_of_ file
Download secured file requiring username and password
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.
Syntax
wget –user=username –password=password http://location_of_ file
This can be used for both ftp and http sites.