Wget Command Examples
Wget is a powerful command-line utility for downloading files from the web. It supports HTTP, HTTPS, and FTP protocols, and offers a wide range of options for controlling downloads. Below are some common and useful Wget command examples.
Basic File Download
To download a file from a given URL:
wget <url>
Downloading Multiple Files
You can download multiple files by listing their URLs:
wget <url1> <url2> <url3>
Renaming Downloaded Files
Use the -O option to specify a different output filename:
wget <url> -O <outfile>
Specifying Download Directory
The -P option allows you to choose the directory where files will be saved:
wget -P <dir> <url>
Resuming Aborted Downloads
If a download is interrupted, you can resume it using the -c option:
wget -c <url>
Downloading from a URL List File
For a large number of URLs, you can list them in a text file and use the -i option:
wget -i url_list.txt
Mirroring a Web Page Locally
To download a web page and its assets (like images, CSS, JS) to view it offline:
wget -pk <url>
Mirroring an Entire Website
This command recursively downloads an entire website. Be cautious with this on large sites:
wget -mk <url>
Downloading Files with Patterns
Wget can download files that follow a pattern, such as numbered archives:
wget http://example.com/files-{1..15}.tar.bz2
Downloading Files by Extension
If directory indexing is enabled on a server, you can download files with specific extensions:
wget -r -l1 -A.extension http://example.com/directory
Displaying Response Headers
To download only response headers and display them on standard output:
wget -S --spider -O - <url>
Changing the User-Agent
Some websites block default Wget user agents. You can change it with the -U option:
wget -U 'Your Custom User-Agent' <url>
Limiting Download Speed
To prevent Wget from consuming too much bandwidth, you can limit the download rate:
wget --limit-rate=500k <url>