wget Command in Linux with Examples
wget Command
wget Command is used to download packages or files directly from the Link. It helps for non-interactive download of files from the Web. This command supports HTTP, HTTPS, and FTP protocols, and retrieval through HTTP proxies. It is mainly designed for slow or unstable connections. It attempts to download until the whole file is retrieved when the download stops due to network problem.
Before using wget command first make sure that wget package is installed or not. You can confirm it by using the below command.
[root@linuxhelp Desktop]# rpm -qa wget
wget-1.12-1.8.el6.x86_64
If not installed, you can install it using the below command
[root@linuxhelp Desktop]# yum -y install wget
Downloading Single File
The following wget command is used to download a single file.
Syntax:
wget [download file URL]
Example:
During downloading process, it show the download progress, size, date and time.
[root@linuxhelp ~]# wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm --2016-03-03 15:36:10-- https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm Resolving dl.google.com... 74.125.200.190, 74.125.200.91, 74.125.200.93,... Connecting to dl.google.com|74.125.200.190|:443... Connected. HTTP request sent, awaiting response... 200 OK Length: 48424175 (46M) [application/x-redhat-package-manager] Saving to: “ google-chrome-stable_current_x86_64.rpm” 100%[=================================================================================> ] 48,424,175 127K/s in 6m 22s 2016-03-03 15:42:34 (124 KB/s) - “ google-chrome-stable_current_x86_64.rpm” saved [48424175/48424175] [root@linuxhelp ~]# ll total 94672 drwxr-xr-x. 3 root root 4096 Mar 3 15:25 Desktop drwxr-xr-x. 2 root root 4096 Dec 24 05:28 Documents -rw-r--r-- 1 root root 48424175 Mar 3 01:46 google-chrome-stable_current_x86_64.rpm drwxr-xr-x. 2 root root 4096 Dec 24 05:28 Music
Naming Download File
Use the following command to provide name for a new download file.
Syntax:
wget -O [filename] [download URL]
Example:
[root@linuxhelp ~]# wget -O google_chrome https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm --2016-03-03 15:51:27-- https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm Resolving dl.google.com... 74.125.68.136, 74.125.68.93, 74.125.68.190, ... Connecting to dl.google.com|74.125.68.136|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 48424175 (46M) [application/x-redhat-package-manager] Saving to: “ google_chrome” 100%[=================================================================================> ] 48,424,175 500K/s in 1m 51s 2016-03-03 15:53:19 (426 KB/s) - “ google_chrome” saved [48424175/48424175] [root@linuxhelp ~]# ll total 94672 drwxr-xr-x. 3 root root 4096 Mar 3 15:25 Desktop drwxr-xr-x. 2 root root 4096 Dec 24 05:28 Documents -rw-r--r-- 1 root root 48424175 Mar 3 01:46 google_chrome -rw-r--r-- 1 root root 48424175 Mar 3 01:46 google-chrome-stable_current_x86_64.rpm drwxr-xr-x. 2 root root 4096 Dec 24 05:28 Music
Downloading Multiple Files Using Different Protocols
The following command can be used to download multiple files using different protocols
Syntax:
wget [download URL] [download URL with another protocol]
Example:
[root@linuxhelp ~]# wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz
--2016-03-03 15:59:55-- https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
Resolving dl.google.com... 74.125.68.93, 74.125.68.190, 74.125.68.136, ...
Connecting to dl.google.com|74.125.68.93|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 48424175 (46M) [application/x-redhat-package-manager]
Saving to: “ google-chrome-stable_current_x86_64.rpm.1”
100%[=================================================================================> ] 48,424,175 465K/s in 1m 47s
2016-03-03 16:01:42 (442 KB/s) - “ google-chrome-stable_current_x86_64.rpm.1” saved [48424175/48424175]
--2016-03-03 16:01:42-- http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz
Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b
Connecting to ftp.gnu.org|208.118.235.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2455995 (2.3M) [application/x-gzip]
Saving to: “ elisp-manual-21-2.8.tar.gz”
100%[=================================================================================> ] 2,455,995 437K/s in 7.1s
2016-03-03 16:01:50 (336 KB/s) - “ elisp-manual-21-2.8.tar.gz” saved [2455995/2455995]
FINISHED --2016-03-03 16:01:50--
Downloaded: 2 files, 49M in 1m 54s (435 KB/s)
Download multiple files from a text file
Execute the following command to download multiple files from a text file.
Syntax:
wget -i [text file name]
Example:
[root@linuxhelp ~]# wget -i Desktop/download-file.txt
--2016-03-03 16:05:59-- https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
Resolving dl.google.com... 74.125.200.93, 74.125.200.136, 74.125.200.91, ...
Connecting to dl.google.com|74.125.200.93|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 48424175 (46M) [application/x-redhat-package-manager]
Saving to: “ google-chrome-stable_current_x86_64.rpm”
100%[=================================================================================> ] 48,424,175 450K/s in 3m 12s
2016-03-03 16:09:10 (247 KB/s) - “ google-chrome-stable_current_x86_64.rpm” saved [48424175/48424175]
--2016-03-03 16:09:10-- http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz
Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b
Connecting to ftp.gnu.org|208.118.235.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2455995 (2.3M) [application/x-gzip]
Saving to: “ elisp-manual-21-2.8.tar.gz.1”
100%[=================================================================================> ] 2,455,995 239K/s in 19s
2016-03-03 16:09:32 (124 KB/s) - “ elisp-manual-21-2.8.tar.gz.1” saved [2455995/2455995]
FINISHED --2016-03-03 16:09:32--
Downloaded: 2 files, 49M in 3m 31s (236 KB/s)
Resume incomplete download
-c option is used to resume incomplete download of the file where it stopped due to network errors. If &ndash c is not used to resume the download then wget command will add .1 extensions at the end of file.
Syntax:
wget -c [download URL]
Example:
[root@linuxhelp ~]# wget -c http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz
First we are downloading the file using the simple wget command and then manually breaking the downloading and in next command we are using the resuming option ‘ -c’
[root@linuxhelp ~]# wget http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz --2016-03-03 16:22:32-- http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b Connecting to ftp.gnu.org|208.118.235.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2455995 (2.3M) [application/x-gzip] Saving to: “ elisp-manual-21-2.8.tar.gz” 37% ==============================> ] 915,902 101K/s eta 17s ^C ####Manually braked and continued using the resuming option [root@linuxhelp ~]# wget -c http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz --2016-03-03 16:23:07-- http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b Connecting to ftp.gnu.org|208.118.235.20|:80... connected. HTTP request sent, awaiting response... 206 Partial Content Length: 2455995 (2.3M), 1516925 (1.4M) remaining [application/x-gzip] Saving to: “ elisp-manual-21-2.8.tar.gz” 100%[+++++++++++++++++++++++++++++++==================================================> ] 2,455,995 58.2K/s in 20s 2016-03-03 16:23:28 (73.2 KB/s) - “ elisp-manual-21-2.8.tar.gz” saved [2455995/2455995]
Download Files In Background
&ndash b option is used to download files in background. Logs are saved in wget-log file in current directory.
Syntax:
wget -b [download URL]
Example:
[root@linuxhelp ~]# wget -b https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
Continuing in background, pid 6589.
Output will be written to “ wget-log” .
Restricting Download Speed Limits
To restrict the download speed to certain limit use the option &ndash limit-rate=10k and logs are saved in /wget/log.txt file.
Syntax:
wget -c --limit-rate=[size] [log file name] [download URL]
Example:
[root@linuxhelp ~]# wget -c --limit-rate=100k http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz --2016-03-03 16:41:47-- http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b Connecting to ftp.gnu.org|208.118.235.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2455995 (2.3M) [application/x-gzip] Saving to: “ elisp-manual-21-2.8.tar.gz” 21% [================> ] 528,208 43.9K/s eta 45s ^ C #####manually breaked continued by replacing the speed to 10k [root@linuxhelp ~]# wget -c --limit-rate=10k http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz --2016-03-03 16:42:10-- http://ftp.gnu.org/gnu/emacs/elisp-manual-21-2.8.tar.gz Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b Connecting to ftp.gnu.org|208.118.235.20|:80... connected. HTTP request sent, awaiting response... 206 Partial Content Length: 2455995 (2.3M), 1914755 (1.8M) remaining [application/x-gzip] Saving to: “ elisp-manual-21-2.8.tar.gz” 100% [++++++++++++++++++================================================================> ]757,142 10.0K/s eta 2m 46s 2016-03-03 16:09:32 (124 KB/s) - “ elisp-manual-21-2.8.tar.gz.1” saved [2455995/2455995] In the above output you can see speed limit varies. In 21% the speed is 43.9K/s and in the 100% the speed is 10.0K/s
Download a website including all the linked pages and files
To download a whole website including all the linked pages and files, the following command is used.
Syntax:
wget ??execute robots=off ??recursive ??no-parent ??continue ??no-clobber [website URL]
Example:
[user1@linuxhelp Desktop]# wget ??execute robots=off ??recursive ??no-parent ??continue ??no-clobber https://www.howtopronounce.com/
--2016-02-09 16:53:43-- http://%E2%80%90%E2%80%90execute/
Resolving ??execute... failed: Name or service not known.
wget: unable to resolve host address “ ??execute”
.
.
.
Connecting to www.howtopronounce.com|50.22.40.138|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “ index.html”
[ ] 36,313 137K/s in 0.3s
2016-02-09 16:53:47 (137 KB/s) - “ index.html” saved [36313]
FINISHED --2016-02-09 16:53:47--
Downloaded: 1 files, 35K in 0.3s (137 KB/s)
Download all the mp4 files from a URL
To download all mp4 files from a URL, use the following command.
Syntax:
wget --level=1 --recursive --no-parent --accept mp4,MP4 [website URL]
Example:
[root@linuxhelp ~]# wget --level=1 --recursive --no-parent --accept mp4,MP4 http://download.wavetlan.com/SVV/Media/HTTP/http-mp4.htm
--2016-03-03 17:04:01-- http://download.wavetlan.com/SVV/Media/HTTP/http-mp4.htm
Resolving download.wavetlan.com... 207.176.222.134
Connecting to download.wavetlan.com|207.176.222.134|:80... Connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “ download.wavetlan.com/SVV/Media/HTTP/http-mp4.htm”
[ ] 28,428 13.2K/s in 2.1s
2016-03-03 17:04:05 (13.2 KB/s) - “ download.wavetlan.com/SVV/Media/HTTP/http-mp4.htm” saved [28428]
.
.
.
Length: 1124814 (1.1M)
Saving to: “ download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test1_Talkinghead_mp4_480x360.mp4”
29% [=========================> ] 329,048 17.5K/s eta 41s
Comments ( 0 )
No comments available