Linux Command Reference ยท Networking
Linux wget command
Reference for the Linux wget command: download files, resume interrupted transfers, rename output, mirror sites, limit speed, and check exit codes in scripts.
wget downloads files over HTTP, HTTPS and FTP. It is built for non-interactive use: it keeps going after you log out, retries on failure, resumes partial files and can follow links to mirror a whole site. Unlike curl, it saves to a file by default and keeps the remote name.
wget https://example.com/archive.tar.gz wget -c -O out.iso https://example.com/big.iso wget -r -np -l 2 https://example.com/docs/
Try it
Neither wget nor network access exists in our sandbox, so downloads are read-only. The runnable example does the string work scripts need around a download: picking a file name from a URL and building an output path.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
wget [OPTION]... [URL]...
| Option | Description |
|---|---|
-O FILE |
Write to FILE (-O - writes to standard output). |
-P DIR |
Save into this directory. |
-c |
Continue a partial download. |
-q |
Quiet. |
-nv |
Less verbose than default, but still prints results. |
--show-progress |
Show a progress bar even with -q. |
-i FILE |
Read URLs from a file. |
-b |
Go to the background; log to wget-log. |
-t N, --tries=N |
Number of attempts (default 20). |
-T SEC, --timeout=SEC |
Network timeout. |
--limit-rate=300k |
Cap the speed. |
-r |
Recursive download. |
-np |
Do not climb above the starting directory. |
-l N |
Recursion depth (default 5). |
-m |
Mirror: -r -N -l inf --no-remove-listing. |
-N |
Skip files that are not newer than the local copy. |
--header="Name: value" |
Add a request header. |
--user=NAME --ask-password |
Credentials, without leaving the password in history. |
--no-check-certificate |
Skip TLS verification (avoid). |
Returns: 0 success; 1 generic error; 2 parse error; 3 file I/O; 4 network failure; 5 TLS failure; 6 authentication; 7 protocol error; 8 server error response such as 404.
Usage notes
- Existing files are not overwritten.
wgetsaves a second download asfile.1,file.2; use-Oor-Nto control this, and-cto continue. -Otruncates the target even if the download then fails, so for important files download to a temporary name andmvinto place.- Resuming with
-conly works if the server supports ranges and the file has not changed; check the checksum afterwards. - Quote URLs with
&or?, otherwise the shell backgrounds the command at the first&. - Be polite when mirroring: combine
-r -npwith--wait=1and--limit-rate, and respectrobots.txt, whichwgetobeys by default. - Piping to a shell (
wget -qO- URL | sh) runs unreviewed code; save and inspect first. - Unattended jobs:
-q --tries=3 --timeout=15plus a check of$?gives a predictable script. - When curl is better: APIs, custom methods, JSON bodies and uploads are easier with
curl; mirroring and retry-heavy downloads suitwget.
Related
curl,scp and sftp,rsync,tar- Lessons: Networking Basics, Packages and Services