Skip to content
Tutorials Center
My learning

Topics

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.

Terminal
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.

Bash Derive file names from URLs

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

Terminal
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. wget saves a second download as file.1, file.2; use -O or -N to control this, and -c to continue.
  • -O truncates the target even if the download then fails, so for important files download to a temporary name and mv into place.
  • Resuming with -c only 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 -np with --wait=1 and --limit-rate, and respect robots.txt, which wget obeys by default.
  • Piping to a shell (wget -qO- URL | sh) runs unreviewed code; save and inspect first.
  • Unattended jobs: -q --tries=3 --timeout=15 plus 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 suit wget.