The wget
command in Linux is a powerful tool for downloading files from the web. It supports HTTP, HTTPS, and FTP protocols and offers features like recursive downloads, resuming interrupted downloads, and background downloads. Below are practical examples to master wget
:
Contents
Download a Single FileDownload and Save with a Different NameDownload in the BackgroundResume an Interrupted DownloadDownload Multiple FilesDownload Files from a ListLimit Download SpeedDownload an Entire Website (Mirror)Download Files via FTPDownload with AuthenticationRetry Failed DownloadsSet a Custom User-AgentDownload Files Matching a PatternExclude Specific File TypesDownload with a Timeout
Download a Single File
wget https://example.com/file.zip
Downloads file.zip
from the specified URL.
Download and Save with a Different Name
wget -O custom_name.zip https://example.com/file.zip
-O
: Saves the file ascustom_name.zip
.
Download in the Background
wget -b https://example.com/large_file.iso
-b
: Runs the download in the background.
Resume an Interrupted Download
wget -c https://example.com/large_file.iso
-c
: Continues downloading a partially downloaded file.
Download Multiple Files
wget https://example.com/file1.zip https://example.com/file2.zip
Downloads multiple files in sequence.
Download Files from a List
wget -i file_list.txt
-i
: Reads URLs fromfile_list.txt
and downloads them.
Limit Download Speed
wget --limit-rate=200k https://example.com/large_file.iso
--limit-rate=200k
: Limits the download speed to 200 KB/s.
Download an Entire Website (Mirror)
wget --mirror --convert-links https://example.com
--mirror
: Recursively downloads the entire website.--convert-links
: Converts links for local viewing.
Download Files via FTP
wget ftp://example.com/file.zip
Downloads file.zip
from an FTP server.
Download with Authentication
wget --user=username --password=password https://example.com/file.zip
--user
and--password
: Authenticate with the server.
Retry Failed Downloads
wget --tries=5 https://example.com/file.zip
--tries=5
: Retries the download up to 5 times.
Set a Custom User-Agent
wget --user-agent="Mozilla/5.0" https://example.com/file.zip
--user-agent
: Mimics a browser user-agent.
Download Files Matching a Pattern
wget -r -A "*.jpg" https://example.com/images/
-r
: Recursively downloads.-A "*.jpg"
: Downloads only.jpg
files.
Exclude Specific File Types
wget -r -R "*.mp4" https://example.com/media/
-R "*.mp4"
: Excludes.mp4
files from the download.
Download with a Timeout
wget --timeout=10 https://example.com/file.zip
--timeout=10
: Sets a 10-second timeout for the connection.
Key Notes:
- Resume Downloads: Always use
-c
for large files to avoid restarting from scratch. - Recursive Downloads: Use
-r
or--mirror
for downloading entire directories or websites. - Permissions: Ensure you have permission to download files from the target server.