Table of contents
1.
Introduction
2.
Exploring Wget's Command-Line Options
2.1.
-v / --version
2.1.1.
Syntax:
2.2.
-h / --help
2.2.1.
Syntax:
2.3.
-o logfile
2.3.1.
Syntax:
2.4.
-b / --background
2.4.1.
Syntax:
2.5.
-a logfile
2.5.1.
Syntax:
2.6.
-i file
2.6.1.
Syntax:
2.7.
-t number / --tries=number
2.7.1.
Syntax:
2.8.
-c
2.8.1.
Syntax:
2.9.
-w seconds
2.9.1.
Syntax:
2.10.
-r / --recursive
2.10.1.
Syntax:
3.
Advantages of Wget Command
4.
Disadvantages of Wget Command
5.
Frequently Asked Questions
5.1.
What does the wget command do?
5.2.
How to install using wget in Linux?
5.3.
How do you download via wget?
5.4.
What is the difference between curl and wget?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

Wget Command in Linux

Author Riya Singh
0 upvote

Introduction

Wget command stands for 'web get,' is a versatile and free command-line tool for downloading files from the internet. It operates seamlessly in the background, allowing users to disconnect from the system while it efficiently fetches files non-interactively.

Wget is a free utility for non-interactive downloading of files from the web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies. 

wget command in linux

This guide will dissect each command, providing a detailed understanding of Wget's capabilities.

Exploring Wget's Command-Line Options

Let’s dive deeper into the wget’s command line options. 

Option Description
-r, --recursive Enables recursive downloading of files and directories.
-np, --no-parent Restricts downloading to the current hierarchy.
-P, --directory-prefix=PREFIX Sets the directory where files are saved.
-A, --accept=LIST Downloads only files with extensions in the list.
-R, --reject=LIST Ignores files with extensions in the list.
-nc, --no-clobber Skips downloading if a file with the same name exists.
-N, --timestamping Downloads files only if newer than the local copy.
-q, --quiet Suppresses output, except for errors and download bar.
-O, --output-document=FILE Specifies the output file name.
-U, --user-agent=AGENT Sets the User-Agent header for the HTTP request.
-h, --help Displays help information about wget options.

-v / --version

Description: This option is used to display the version of Wget installed on your system, providing insight into the specific build and features available to you.

Syntax:

wget -v

-h / --help

Description: This option is used to display a help message, listing all the command-line options available with Wget. It serves as a quick reference guide for users.

Syntax:

wget -h

-o logfile

Description: This option is used to log all messages from Wget to a specified logfile. It is useful for saving a record of the download process, which can be reviewed later for information or troubleshooting.

Syntax:

wget -o logfile [URL]

-b / --background

Description: This option sends the download process to the background upon initiation. It allows the user to continue with other tasks without having to wait for the download to complete.

Syntax:

wget -b [URL]

-a logfile

Description: This option appends messages to a specified logfile without overwriting the existing content. It is useful for maintaining a continuous log over multiple Wget operations.

Syntax:

wget -a logfile [URL]

-i file

Description: This option reads URLs from a specified file, allowing for batch downloading. It is particularly useful when dealing with multiple downloads, keeping the command line uncluttered.

Syntax:

wget -i file

-t number / --tries=number

Description: This option sets the number of retries for a download to a specified number. If a download fails, Wget will retry the specified number of times before giving up.

Syntax:

wget -t number [URL]

-c

Description: This option is used to resume a partially downloaded file. If a download is interrupted, Wget can pick up where it left off, saving time and bandwidth.

Syntax:

wget -c [URL]

-w seconds

Description: This option sets the interval between retrievals to a specified number of seconds. It is recommended to use this option to reduce the load on the server and to adapt to network errors or downtimes.

Syntax:

wget -w seconds [URL]

-r / --recursive

Description: This option enables recursive retrieval of websites. Wget will follow links and download entire directory structures, mirroring the layout of the original site.

Syntax:

wget -r [URL]

Advantages of Wget Command

Autonomy: Wget operates independently, allowing for unattended downloads.
 

Resilience: It can resume downloads and is designed to handle unstable network connections.
 

Versatility: Wget supports HTTP, HTTPS, FTP protocols, and proxy servers.

Disadvantages of Wget Command

Complexity: The multitude of options can be overwhelming for new users.
 

No GUI: The lack of a graphical interface might deter some users.
 

Sequential Downloads: Wget processes downloads one at a time, which may not be as efficient as parallel downloads.

Frequently Asked Questions

What does the wget command do?

wget is a command-line tool for downloading files from the internet. It supports various protocols, including HTTP, HTTPS, and FTP.

How to install using wget in Linux?

You can use wget to download files. For example: wget https://example.com/file.zip.

How do you download via wget?

You can use the command wget followed by the URL of the file you want to download.

What is the difference between curl and wget?

Both download tools, curl is feature-rich with support for various protocols and outputs to the console. wget is simpler, focusing on downloads with options for recursive fetching.

Conclusion

In this blog, we learn about wget command in linux. The wget command in Linux stands as a versatile and powerful tool for simplifying file downloads from the internet. Its straightforward syntax, support for various protocols, and customizable options make it an essential utility for users and administrators alike. 

Recommended Reads:  features of linux operating system

You can refer to our guided paths on the Coding Ninjas. You can check our course to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. 

Also, check out some of the Guided Paths on topics such as Data Structure and AlgorithmsCompetitive ProgrammingOperating SystemsComputer Networks, DBMSSystem Design, etc., as well as some Contests, Test Series, and Interview Experiences curated by top Industry Experts.

Live masterclass