What is wget command?
Use of wget command in Linux is done to download 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.
Contents – Use wget command in Linux with Examples
- Download Single file with use wget command in Linux
- Download File with wget command to different local directory other than current working directory
- Download without standard output – wget quiet mode
- Change the name of file downloaded file with wget command
- Resume partial download with wget command
- Two methods to Download of Multiple files using wget command
- Restrict usage of Bandwidth while using wget command
- Logging of output of wget command
- Use wget in background
- Download from an untrusted location / without valid certificate
- Mirror a website with wget command in Linux
- Download secured file requiring username and password with wget command
Use of wget command in Linux with Examples
Single file with use wget command in Linux
To download a single file using wget command use below command. Here you will use wget with web location of file to download.
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 File with wget command to different local directory other than current working directory
wget command by default downloads file is current working directory. To download file to any other directory other than current working directory use “-P” switch.
Syntax
wget -P /local/location/of/file http://location_of_ file
Example
wget -P /home/infojinx/Documents/ https://infojinx.com/testfile.iso
Download without standard output – wget quiet mode
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.
Change the name of file downloaded with wget command
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 partial download with wget command
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 for initial download 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.
Two methods to Download of Multiple files using wget command
By providing names of files – In this method location of all files are provided.
Download multiple files with wget command
Syntax
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.
Syntax
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
Syntax
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.
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 with wget command in Linux
To mirror a complete website –m switch can be used.
Syntax
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.
Syntax
wget –user=username –password=password http://location_of_ file