Wget is a Linux command-line tool used for downloading files from the internet. It is a non-interactive tool that can download files in the background, allowing you to perform other tasks while the download is in progress. Wget supports HTTP, HTTPS, and FTP protocols and can be used to download files from both public and password-protected websites.
Overview
The basic syntax for using wget is as follows:
wget [options] [URL]
To download a file using wget, simply provide the URL of the file you want to download. For example, to download a file named “example.zip” from a website, you would use the following command:
wget https://example.com/example.zip
By default, wget will download the file to the current working directory. You can specify a different directory by using the -P
option followed by the directory path. For example, to download the file to a directory named “downloads”, you would use the following command:
wget -P /path/to/downloads https://example.com/example.zip
Wget can also be used to download multiple files at once. To do this, create a text file containing the URLs of the files you want to download, with each URL on a separate line. Then, use the -i
option followed by the path to the text file. For example, to download all the files listed in a file named “urls.txt”, you would use the following command:
wget -i /path/to/urls.txt
Wget also supports resuming interrupted downloads. To resume a download, use the -c
option followed by the URL of the file you want to resume. For example, to resume a download of a file named “example.zip”, you would use the following command:
wget -c https://example.com/example.zip
Options
The following table lists the available options for the wget command:
Option | Description |
---|---|
-P |
Specifies the directory where downloaded files will be saved |
-c |
Resumes a partially downloaded file |
-i |
Downloads files listed in a text file |
-r |
Downloads files recursively |
-np |
Disables downloading files from parent directories |
-N |
Downloads only files that are newer than existing files |
-q |
Runs wget in quiet mode |
-O |
Specifies the name of the downloaded file |
-U |
Specifies the user agent string to use |
-t |
Specifies the number of retries if a download fails |
-T |
Specifies the timeout for a download |
-b |
Runs wget in the background |
-a |
Appends output to a log file |
Troubleshooting Tips
- If you receive an error message indicating that the download failed, try using the
-t
option to increase the number of retries. For example,wget -t 10 https://example.com/example.zip
. - If you receive an error message indicating that the download timed out, try using the
-T
option to increase the timeout period. For example,wget -T 60 https://example.com/example.zip
. - If you are having trouble downloading a file from a password-protected website, try using the
--user
and--password
options to provide your login credentials. For example,wget --user=username --password=password https://example.com/example.zip
.
Notes
- Wget is a powerful tool that can be used to download large files and entire websites. However, be aware that downloading large amounts of data can consume a lot of bandwidth and may be subject to restrictions by your internet service provider.
- Always ensure that you have the legal right to download any files you are downloading with wget. Some websites may have terms of service or copyright restrictions that prohibit downloading their content without permission.