Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. Bash Dictionary
  3. wget

wget

wget is a command-line tool for downloading files. It supports HTTP, HTTPS, and FTP, and handles recursive downloads and background execution.

Syntax

Run a basic download.

wget URL

Save with a specific filename.

wget -O output-filename URL

Specify a destination directory.

wget -P target-directory URL

Download in the background.

wget -b URL

Recursively download (mirror an entire site).

wget -r URL

Run in quiet mode (no progress output).

wget -q URL

Options

OptionDescription
-O fileSpecifies the filename to save the download as.
-P directorySpecifies the directory to save the downloaded file in.
-qRuns in quiet (silent) mode — suppresses progress and messages.
-vShows verbose output (default behavior).
-bRuns the download in the background.
-cResumes an interrupted download.
-rDownloads recursively.
-l depthSets the recursion depth for recursive downloads (use with -r).
-npPrevents ascending to the parent directory during recursive downloads (use with -r).
-A extensionFilters downloads by file extension.
--limit-rate=rateLimits the download speed (e.g., 1m for 1 MB/s).
--tries=countSets the number of retry attempts on failure.
--timeout=secondsSets the connection timeout in seconds.
-i fileReads a list of URLs from a text file and downloads them all.
--user-agent=stringSpecifies the User-Agent string to use.

Sample Code

Download a file. By default, wget shows detailed progress output.

wget https://example.com/file.txt
--2026-03-06 12:00:00--  https://example.com/file.txt
Resolving example.com... 93.184.216.34
Connecting to example.com|93.184.216.34|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1024 (1.0K) [text/plain]
Saving to: 'file.txt'

file.txt            100%[===================>]   1.00K  --.-KB/s    in 0s

2026-03-06 12:00:01 (10.0 MB/s) - 'file.txt' saved [1024/1024]

Save the downloaded file under a specific name.

wget -O /tmp/archive.tar.gz https://example.com/release-1.0.tar.gz

Download a file into a specific directory.

wget -P /opt/downloads https://example.com/file.zip

Download in the background with a speed limit.

wget -b --limit-rate=500k https://example.com/large-file.iso
Continuing in background, pid 12345.
Output will be written to 'wget-log'.

If a download was interrupted, use -c to resume from where it left off.

wget -c https://example.com/large-file.iso

Read a list of URLs from a file and download them all at once.

cat urls.txt
https://example.com/file1.txt
https://example.com/file2.txt
https://example.com/file3.txt
wget -i urls.txt -P downloads/

Recursively download only images from a site, up to 2 levels deep.

wget -r -l 2 -A jpg,png -np https://example.com/gallery/

When using wget in a script, add -q (quiet) to suppress output and check the exit code for error handling.

download.sh
wget -q -O /tmp/data.json https://api.example.com/data
echo "Exit code: $?"
bash download.sh
Exit code: 0

Notes

wget excels at resuming interrupted downloads with the -c option, making it well-suited for large file downloads. Combining -r (recursive) with -A (extension filter) lets you batch-download only specific file types from a site.

When embedding wget in scripts, use -q (quiet) to suppress log output and check the exit code ($?) to detect errors. If you need fine-grained control over HTTP requests, consider using curl instead.

If you find any errors or copyright issues, please .