Linux Administrator

10 Wget Command Examples In Linux

Wget utility is free and license is under GNU GPL Licencse. It is used to retrieving files using HTTP, HTTPS, and FTP the most widely-used internet protocols. It is a non-interactive command line tool. This utility can be install any Unix/Linux Operating system including Windows and MAC OS. It is designed in such way so that it works in slow network connections. It automatically start download where it was left off in case of network issue.

In this article I will describe 10 wget command with examples.

Verify Wget Utility is Installed or Not

# rpm -qa wget
wget-1.12-1.4.el6.i686

If it is not installed on system install it using YUM command or you can also download binary package at http://ftp.gnu.org/gnu/wget/.

# yum -y install wget

Wget Examples

1. Download Single File

Follow the below command to download single file. It will stores in current directory. You can also show the download progress, size, date and time during download process.

# wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz

Sample Output:

--2017-04-20 23:16:28--  http://ftp.gnu.org/gnu/wget/wget-1.5.3.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: 446966 (436K) [application/x-gzip]
Saving to: `wget-1.5.3.tar.gz'

100%[===========================================================================================================>] 446,966     1.13M/s   in 0.4s

2017-04-20 23:16:31 (1.13 MB/s) - `wget-1.5.3.tar.gz' saved [446966/446966]

You can also download file from cURL. Refer to cURL examples to understand how to use cURL effectively

2. Save File with Different Name

You can download file with different file name using -O option with file name here I have given wget.zip file name show below.

# wget -O wget.zip http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz

Sample output:

--2017-04-20 23:18:13--  http://ftp.gnu.org/gnu/wget/wget-1.5.3.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: 446966 (436K) [application/x-gzip]
Saving to: `wget.zip'

100%[===========================================================================================================>] 446,966     1.11M/s   in 0.4s

2017-04-20 23:18:15 (1.11 MB/s) - `wget.zip' saved [446966/446966]

3. Download Multiple Files With FTP and HTTP Protocol

You can also download multiple files using FTP and HTTP protocol with wget command like below.

# wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz ftp://ftp.gnu.org/gnu/wget/wget-1.10.1.tar.gz.sig

Sample output:

--2017-04-20 23:22:20--  http://ftp.gnu.org/gnu/wget/wget-1.5.3.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: 446966 (436K) [application/x-gzip]
Saving to: `wget-1.5.3.tar.gz'

100%[===========================================================================================================>] 446,966     1.12M/s   in 0.4s

2017-04-20 23:22:21 (1.12 MB/s) - `wget-1.5.3.tar.gz' saved [446966/446966]

--2017-04-20 23:22:21--  ftp://ftp.gnu.org/gnu/wget/wget-1.10.1.tar.gz.sig
           => `wget-1.10.1.tar.gz.sig'
Connecting to ftp.gnu.org|208.118.235.20|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD /gnu/wget ... done.
==> SIZE wget-1.10.1.tar.gz.sig ... 65
==> PASV ... done.    ==> RETR wget-1.10.1.tar.gz.sig ... done.
Length: 65

100%[===========================================================================================================>] 65          --.-K/s   in 0.006s

2017-04-20 23:22:21 (10.8 KB/s) - `wget-1.10.1.tar.gz.sig' saved [65]

FINISHED --2017-04-20 23:22:21--
Downloaded: 2 files, 437K in 0.4s (1.10 MB/s)

4. Download File Using Text File URLs

You can also download file reading URL’s from a file. You will need to create download.txt and put the series of URL’s to download.

# vim download.txt
http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz
ftp://ftp.gnu.org/gnu/wget/wget-1.10.1.tar.gz.sig

Save and close file.

Now execute below command to download files reading above mention URL’s.

# wget -i download.txt

Sample output:

--2017-04-20 23:28:29--  http://ftp.gnu.org/gnu/wget/wget-1.5.3.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: 446966 (436K) [application/x-gzip]
Saving to: `wget-1.5.3.tar.gz'

100%[==============================================================================================>] 446,966     1.14M/s   in 0.4s

2017-04-20 23:28:30 (1.14 MB/s) - `wget-1.5.3.tar.gz' saved [446966/446966]

--2017-04-20 23:28:30--  ftp://ftp.gnu.org/gnu/wget/wget-1.10.1.tar.gz.sig
           => `wget-1.10.1.tar.gz.sig'
Connecting to ftp.gnu.org|208.118.235.20|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD /gnu/wget ... done.
==> SIZE wget-1.10.1.tar.gz.sig ... 65
==> PASV ... done.    ==> RETR wget-1.10.1.tar.gz.sig ... done.
Length: 65

100%[==============================================================================================>] 65          --.-K/s   in 0s

2017-04-20 23:28:30 (7.75 MB/s) - `wget-1.10.1.tar.gz.sig' saved [65]

FINISHED --2017-04-20 23:28:30--
Downloaded: 2 files, 437K in 0.4s (1.14 MB/s)

5. Resume Uncompleted Download

If you are downloading large file due to some reason you can stop downloading and again can resume download the same file where it was left off with using -c option. But remember if you start downloading file without -c option wget will add .1 extension at the end of file, considering as a fresh download.

# wget -c http://mirrors.hns.net.in/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveDVD.iso

Sample output:

--2017-04-20 23:28:29--  http://mirrors.hns.net.in/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveDVD.iso
Resolving mirrors.hns.net.in... 111.91.91.34, 2401:4800::111:91:91:34
Connecting to mirrors.hns.net.in|111.91.91.34|:80... connected.
HTTP request sent, awaiting response... 206 Partial Content
Length: 1761607680 (1.6G), 1758132697 (1.6G) remaining [application/octet-stream]
Saving to: CentOS-6.3-x86_64-LiveDVD.iso
51% [=================================================                                  ] 3,877,262   47.0K/s  eta 10h 27m ^

6. Download File With Appended .1 in File Name

If you start downloading without –c option wget will add .1 at the end of file name and start with fresh download. If .already exist .2 append at the end of file.

# wget http://mirrors.hns.net.in/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveDVD.iso

Sample output:

--2017-04-20 23:28:30--  http://mirrors.hns.net.in/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveDVD.iso
Resolving mirrors.hns.net.in... 111.91.91.34, 2401:4800::111:91:91:34
Connecting to mirrors.hns.net.in|111.91.91.34|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1761607680 (1.6G) [application/octet-stream]
Saving to: CentOS-6.3-x86_64-LiveDVD.iso.1
18% [==================                                                                 ] 172,436     59.2K/s

You can see the file with .1 extension appended at the end of file.

# ls -l CentOS*
-rw-r--r--. 1 root root 3877262 Apr  20 23:40 CentOS-6.3-x86_64-LiveDVD.iso
-rw-r--r--. 1 root root  181004 Apr  20 23:45 CentOS-6.3-x86_64-LiveDVD.iso.1

7. Download File in Background

You can also download file in background using –b option, after start downloading all out put will go in txt file lile below.

# wget -b /tmp/output.txt ftp://ftp.iinet.net.au/debian/debian-cd/6.0.5/i386/iso-dvd/debian-6.0.5-i386-DVD-1.iso
Continuing in background, pid 3550.

8. Set Download Speed Limits

You can also restrict download speed limits using –limit-rate=100k the download speed limit is restricted to 100k and the logs will be created under /tmp/output.txt as shown below.

# wget -c --limit-rate=100k  /tmp/output.txt  ftp://ftp.iinet.net.au/debian/debian-cd/6.0.5/i386/iso-dvd/debian-6.0.5-i386-DVD-1.iso

Sample output:

/tmp/output.txt: Scheme missing.
--2017-04-20 23:50:30--  ftp://ftp.iinet.net.au/debian/debian-cd/6.0.5/i386/iso-dvd/debian-6.0.5-i386-DVD-1.iso
=> debian-6.0.5-i386-DVD-1.iso
esolving ftp.iinet.net.au... 203.0.178.32
Connecting to ftp.iinet.net.au|203.0.178.32|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /debian/debian-cd/6.0.5/i386/iso-dvd ... done.
==> SIZE debian-6.0.5-i386-DVD-1.iso ... 4691312640
==> PASV ... done.    ==> REST 2825236 ... done.
==> RETR debian-6.0.5-i386-DVD-1.iso ... done.
Length: 4688487404 (4.4G), 4685662168 (4.4G) remaining (unauthoritative)
0% [                                                                                    ] 3,372,160   35.5K/s  eta 28h 39m

9. Download Restricted HTTP and HTTP Sites

You can download restricted HTTP and FTP sites using –http-user=username, –http-password=password & –ftp-user=username, –ftp-password=password option.

Restricted HTTP

# wget --http-user=narad --http-password=password http://mirrors.hns.net.in/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveDVD.iso

Restricted FTP

# wget --ftp-user=narad --ftp-password=password ftp://ftp.iinet.net.au/debian/debian-cd/6.0.5/i386/iso-dvd/debian-6.0.5-i386-DVD-1.iso

10. Check Wget Version and Help

You can find the wget version and help using -version and -help option as needed.

# wget --version
# wget --help

I hope this article will help for daily administrative task. If you want to know more about wget go to its man page.

Please share your thought using comment section if I have missed out anything.

Thanks:)

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment