wget commands cheat sheet
Downloading files
-
wget https://example.com/file.zipDownloads the file to the current directory, under the name at the end of the URL. When a file with the same name already exists, the new file is saved as file.zip.1 and the existing file stays as it is.
-
wget -O backup.zip https://example.com/file.zipSaves the file under a name you choose. An existing file with the same name is overwritten, as with output redirection in the shell.
-
wget -P /home/user/downloads https://example.com/file.zipSaves the file to another directory instead of the current one.
-
wget -c https://example.com/large.isoResumes an interrupted download from where it stopped. When the server doesn't support resuming, wget starts over and overwrites the existing file.
-
wget -nc https://example.com/file.zipSkips the download when a file with the same name already exists in the directory, instead of saving another copy.
-
wget -N https://example.com/file.zipDownloads the file only when the version on the server is newer than the local file or when the file sizes differ. The check relies on the modification date the server returns in the Last-Modified header.
-
wget --content-disposition "https://example.com/download?id=5"Saves the file under the name the server suggests in the Content-Disposition header, instead of a name taken from the URL. The documentation describes this support as experimental.
-
wget -i urls.txtDownloads every URL in the urls.txt file, one URL per line.
-
cat urls.txt | wget -i -Reads the list of URLs from standard input, for example from the output of another command.
-
wget --max-redirect=5 https://example.com/file.zipLimits the number of redirects wget follows. The default is 20 redirects.
Progress, output, and log files
-
wget -q https://example.com/file.zipDownloads with no output at all, which is handy in scripts.
-
wget -nv https://example.com/file.zipShows short output: one line per file and error messages, without the progress bar.
-
wget -q --show-progress https://example.com/file.zipHides all the messages and shows only the progress bar, which is handy when downloading several files.
-
wget -b https://example.com/large.isoMoves the download to the background and frees the command line. When no log file is set, the messages are written to the wget-log file in the current directory.
Example:
Continuing in background, pid 4120. -
tail -f wget-logShows the progress of a download running in the background. Press Ctrl+C to leave the view, and the download keeps running.
-
wget -o download.log https://example.com/file.zipWrites all the messages to a log file instead of the screen. An existing log file is overwritten.
-
wget -a download.log https://example.com/file.zipAppends the messages to the end of an existing log file instead of overwriting it.
-
wget --progress=dot:mega https://example.com/large.isoShows the progress as dots, with each dot standing for 64KB. Suited to log files, where a regular progress bar creates long lines.
Speed, retries, and waiting
-
wget --limit-rate=500k https://example.com/large.isoLimits the download speed to 500KB per second, so the download doesn't take up all the bandwidth. You can also use m for megabytes and decimal numbers, such as 2.5k.
-
wget -t 5 https://example.com/file.zipSets the number of attempts when the download fails. The default is 20 attempts, but errors such as 404 or a refused connection aren't retried.
-
wget -t 0 --retry-connrefused https://example.com/file.zipRetries without limit, even when the server refuses the connection. Useful while the server restarts. Stop it manually with Ctrl+C when the server doesn't come back up.
-
wget -T 30 https://example.com/file.zipSets a maximum wait of 30 seconds for the name lookup, the connection, and receiving data. The default for receiving data is 900 seconds.
-
wget --wait=2 -i urls.txtWaits 2 seconds between downloads to avoid overloading the server. You can also give minutes, hours, or days with the m, h, and d suffixes.
-
wget --wait=2 --random-wait -i urls.txtVaries the wait time randomly, between 0.5 and 1.5 times the time set with the --wait option.
-
wget -Q 500m -i urls.txtStops after a total of 500MB has been downloaded from the list. The limit doesn't cut off a file that is already downloading and doesn't apply when downloading a single file.
Headers, authentication, and cookies
-
wget --header="Accept-Language: he" https://example.com/Adds a header to the request. You can repeat --header several times.
-
wget --header="Authorization: Bearer TOKEN" https://example.com/export.csvDownloads a file that requires an access token. The token is saved in the command history, so it is better to read it from an environment variable.
-
wget -U "Mozilla/5.0" https://example.com/Sets the identification string (User-Agent) sent to the server, for example when a site returns a different page to command-line tools.
-
wget --user=admin --ask-password https://example.com/private/file.zipLogs in with a username and prompts you to type the password, so the password isn't saved in the command history.
Example:
Password for user 'admin': -
wget --http-user=admin --http-password=secret https://example.com/private/Caution: a password typed on the command line is saved in the history and is visible to other users on the server in the process list. It is better to use the --ask-password option or a .netrc file with restricted permissions.
-
wget --load-cookies cookies.txt https://example.com/members/file.zipSends cookies from a file in Netscape format, for example login cookies exported from the browser.
-
wget --save-cookies cookies.txt --keep-session-cookies https://example.com/Saves the cookies the server sent to a file, including session cookies, for use in later downloads.
HTTPS, certificates, and network
-
wget --no-check-certificate https://example.com/file.zipCaution: skips verification of the server's SSL certificate, which leaves no protection against impersonation. Use it only for a temporary test against a server you know, and never to download files you are going to run.
-
wget --ca-certificate=ca.pem https://example.com/file.zipVerifies the server's certificate against a certificate authority file you provide, for example on an internal network with its own certificate authority.
-
wget -r --https-only https://example.com/docs/In a recursive download, follows HTTPS links only.
-
wget -4 https://example.com/file.zipConnects over IPv4 addresses only. The -6 option connects over IPv6 addresses only.
-
https_proxy=http://proxy.example.com:3128 wget https://example.com/file.zipDownloads through a proxy server set in the https_proxy environment variable. For HTTP URLs, use the http_proxy variable.
-
wget --no-proxy https://example.com/file.zipIgnores the proxy settings in the environment variables and connects directly.
Recursive downloads and site mirroring
-
wget -r https://example.com/docs/Downloads the page and the pages it links to on the same site. The default depth is 5 levels, and the files are saved in a directory named after the domain.
-
wget -r -l 2 https://example.com/docs/Limits the recursive download to a depth of 2 levels. The value inf or 0 means no depth limit.
-
wget -r -np https://example.com/docs/Never goes up to the directories above the one in the URL, so only the contents of /docs/ and below are downloaded.
-
wget -p -k https://example.com/page.htmlDownloads a single page with everything needed to display it, such as images and CSS files, and converts the links for local viewing.
-
wget -m -k -p -np https://example.com/docs/Mirrors a site or a directory for local viewing. The -m option includes a recursive download with no depth limit and date checking (-N), so a repeat run downloads only the files that have changed.
-
wget -m -k -p -E https://example.com/Adds the .html extension to pages whose URL doesn't end with it, such as dynamic pages, so they open properly on your computer.
-
wget -r -np -nd -A pdf https://example.com/files/Downloads only the PDF files from the directory and saves them all in the current directory, without the site's directory structure.
-
wget -r -np -A jpg,png https://example.com/gallery/Downloads only files with the extensions in the list, separated by commas.
-
wget -r -np -R "*.zip,*.iso" https://example.com/files/Downloads all the files except those that match the patterns in the list.
-
wget -r --reject-regex "logout" https://example.com/Skips URLs that match the regular expression, for example logout links or URLs with unneeded parameters.
-
wget -r -np -nH --cut-dirs=2 https://example.com/pub/files/Saves the files without a directory named after the domain (-nH) and skips the first two directory levels in the URL, so the contents of /pub/files/ are saved directly in the current directory.
-
wget -r -H -D example.com,cdn.example.com https://example.com/Allows downloading from other domains too, but only from those in the list. Without -H, a recursive download stays on the same host.
-
wget -m -k -p --wait=1 --limit-rate=200k https://example.com/Mirrors a site at a gentle pace, with a wait between requests and a speed limit, to avoid overloading the site's server.
-
wget -r -e robots=off https://example.com/docs/Ignores the site's robots.txt file and nofollow directives. Use this option only on your own site or with the site owner's permission, and respect the site's terms.
Checking without downloading
-
wget --spider https://example.com/file.zipChecks that the file exists on the server, without downloading it. When the file exists, the exit code is 0, and when the server returns an error such as 404, the exit code is 8.
Example:
Remote file exists. -
wget -S --spider https://example.com/file.zipAlso shows the server's response headers, such as the status code, the file size, and the modification date.
Example:
HTTP/1.1 200 OK -
wget -S -O /dev/null https://example.com/Sends a regular GET request, shows the response headers, and discards the content.
-
wget --spider --force-html -i bookmarks.htmlChecks all the links in an HTML file, for example a bookmarks file exported from the browser.
Output to the screen and to other commands
-
wget -qO- https://example.com/Shows the page content on the screen instead of saving it to a file. The - after -O means standard output, and in this mode link conversion (-k) doesn't work.
-
wget -qO- https://example.com/archive.tar.gz | tar xzDownloads an archive and extracts it right away, without saving the archive file to disk.
-
wget -qO- https://www.ereznet.co.il/ipShows the public IP address of your connection on one line. On a server, the command shows the address the server uses to reach the internet. With -4 or -6, you get the IPv4 address or the IPv6 address separately.
Example:
198.51.100.23 -
wget https://example.com/install.shDownloads an installation script to a file. Read the script before you run it, instead of piping it straight to bash.
-
sha256sum large.isoCalculates the checksum of a downloaded file, so you can compare it with the checksum published on the download site and make sure the file is complete and unchanged.
Exit codes
-
echo $?Shows the exit code of the last command. 0 means the download succeeded, 4 a network failure, 5 an SSL certificate verification failure, 6 an authentication failure, and 8 an error returned by the server, such as 404 or 500.
Example:
0 -
wget -q https://example.com/file.zip || echo "download failed"Runs another command only when the download failed, for example in a backup script or an automated installation.
-
wget -q https://example.com/archive.tar.gz && tar xzf archive.tar.gzMoves on to the next command only when the download succeeded.
Installation and settings
-
wget --versionShows the version and the features it was built with. On Fedora, the wget command runs Wget2 by default, and you can see this in the output.
Example:
GNU Wget 1.25.0 built on linux-gnu. -
sudo dnf install wgetInstalls wget on AlmaLinux, Rocky Linux, and Fedora.
-
sudo apt install wgetInstalls wget on Ubuntu and Debian.
-
echo 'tries = 5' >> ~/.wgetrcSets a default for all of the user's downloads, in the .wgetrc settings file in the home directory.
-
wget -e robots=off -e tries=3 https://example.com/Applies .wgetrc settings for a single run, without changing the file.
No matching commands.
Names and addresses in the examples
The examples on this page use the example.com domain, so replace it with the address you download from. The address https://www.ereznet.co.il/ip is real and returns your public IP address.
wget or curl
wget is built mainly for downloading files: it resumes interrupted downloads, downloads lists of files, and mirrors sites and directories. To check headers, redirects, response times, and API requests, the commands on the curl commands page are more convenient.
wget on Fedora
On Fedora, the wget command runs Wget2 by default, the new version of the tool. According to the Fedora documentation, Wget2 replaces wget in most cases, except for FTP and WARC, and some options behave differently. Run wget --version to check which version is installed.
Downloading sites with respect for their owners
In a recursive download, wget respects the site's robots.txt file. When you mirror a site that isn't yours, add a wait between requests and a speed limit, download only what you need, and respect the site's terms of use.
A Linux VPS gives you full root access over SSH, so you can download files, backups, and system images straight to the server with wget. Monthly traffic is unlimited on every plan, and billing does not depend on how much data the server transfers.
Related pages
wget commands FAQ
How do I resume an interrupted download with wget?
Run the same command again with the -c option, for example wget -c https://example.com/large.iso, in the directory that holds the partial file. wget resumes from where the download stopped. When the server doesn't support resuming, the download starts over.
How do I save a file under a different name or in another directory with wget?
The -O option sets the file name, for example wget -O backup.zip https://example.com/file.zip, and the -P option sets the directory, for example wget -P /home/user/downloads https://example.com/file.zip. With -O, an existing file with the same name is overwritten.
How do I download an entire website with wget for offline viewing?
The wget -m -k -p -np https://example.com/docs/ command downloads the site or the directory with its images and style files, and converts the links so the pages open from your computer. A repeat run downloads only the files that have changed. On a site that isn't yours, add --wait=1 and --limit-rate to avoid overloading the server.
How do I download a large file in the background with wget?
The -b option moves the download to the background and frees the command line, and the messages are written to the wget-log file. To see the progress, run tail -f wget-log. To keep a large download from taking up all the bandwidth, add --limit-rate, and if the connection drops, resume the download with -c.
What is the difference between wget and curl?
wget is built mainly for downloading files: it saves a file by default, resumes interrupted downloads, and downloads sites and directories recursively. curl shows the response on the screen and is especially suited to checking headers, redirects, and API requests. For the common curl commands, see the curl commands page.