Cheat Sheets

Wget Cheat Sheet: Resume, Mirror, Retries, Auth and Spider

Resuming a download with wget -c verifies nothing. wget asks the server for the bytes you don’t have yet and glues them onto the partial file. If that file changed on the server in between, you end up with a corrupt copy and an exit status of 0. That gap is why this wget cheat sheet tells you what each flag does on the wire before it shows you the output that proves it.

Original content from computingforgeeks.com - post 185695

The sheet covers resuming with -c, recursive mirrors, --limit-rate, authentication and custom headers. It continues with retries, background jobs with -b, input lists and the --spider broken-link check, then shows where wget2 behaves differently and when curl is the better tool. You’ll also get the exit codes your scripts branch on. Everything below was run on Ubuntu 26.04.1 LTS with GNU Wget 1.25.0 and Wget2 2.2.0 in November 2026, against an nginx test server called web01, so every error and timing comes from that lab.

The wget cheat sheet at a glance

Use these tables as the short version when you already know the job and only need the syntax. Each row was run on the lab box, and the sections further down show you the output and the traps behind the flags that cause trouble. The same tables make up the printable PDF.

Download and name files

CommandWhat it does
wget URLDownload into the current directory
wget -O name.gz URLSave under a name you choose
wget -P incoming/ URLSave into a directory, created if missing
wget -qO- URLPrint the body to stdout for a pipe
wget -nc URLSkip the download if the file exists
wget -N URLDownload only if the server copy is newer
wget -nv URLOne line per file instead of the progress dump

Resume, rate and quota

CommandWhat it does
wget -c URLResume a partial file with a Range request
wget --limit-rate=200k URLAverage download speed of 200 KB/s
wget -Q 100m -i urls.txtStop starting new files after 100 MB
wget --wait=1 --random-wait -r URLPause between requests in a recursive run

Retries and timeouts

CommandWhat it does
wget --tries=5 URLAt most 5 attempts for transient failures
wget --retry-on-http-error=429,503 URLTreat these HTTP codes as retryable
wget --retry-connrefused URLRetry when the port refuses connections
wget --waitretry=2 URLBack off 1 s, then 2 s between retries
wget --timeout=3 URL3 s DNS, connect and idle-read timeout

Auth, headers and POST

CommandWhat it does
wget --user=deploy --ask-password URLBasic auth, password prompted
wget URL with ~/.netrcBasic auth from a 600-mode netrc file
wget --header="X-Trace-Id: 4f9a2c" URLAdd a request header (repeatable)
wget --user-agent="probe-check/1.0" URLReplace the default Wget/1.25.0 agent
wget -S --spider URLShow response headers, download nothing
wget --post-data='{"k":"v"}' URLPOST a string body
wget --post-file=body.json URLPOST a file as the body

Lists, background and logs

CommandWhat it does
wget -i urls.txtDownload every URL in a file, one per line
wget -B http://web01/files/ -i names.txtResolve relative names against a base URL
wget -i -Read the URL list from stdin
wget -b URLDetach and log to wget-log
wget -o run.log URLWrite messages to a log, overwriting it
wget -a run.log URLAppend messages to a log

Recursive, mirror and spider

CommandWhat it does
wget --mirror -k -E -p -np URLOffline copy with links rewritten
wget -r -l1 -nd -np -A "*.gz" URLGrab matching files from one directory
wget -r -l1 -nd -np -R "log-*" URLSkip a pattern (index.html is still kept)
wget --spider -nv URLCheck one URL exists without saving it
wget --spider -r -l 3 -np -nd -nv -o spider.log URLCrawl and list broken links
wget -e robots=off -r URLIgnore robots.txt on a site you own

TLS and wget2

CommandWhat it does
wget --ca-certificate=lab-ca.pem URLTrust a private CA for this run
wget --no-check-certificate URLSkip verification (warnings only)
wget2 -i urls.txtDownload the list 5 files at a time
wget2 --max-threads=10 -i urls.txtRaise the parallel download count
echo $?Read the exit code after any run

Most of these flags combine, and a recursive run usually carries four or five of them at once. The sections below take them in the order your download meets them, starting with how the file gets its name and ending with crawling a whole site.

Wget never overwrites by default

Run the same wget URL twice and you do not get a fresh copy of the file. You get a second file with .1 on the end, then .2. A nightly cron job fills the directory with numbered copies, while the script that reads log-01.gz keeps reading the first one. Check your build first, because the version line matters later when wget2 enters the picture.

wget --version | head -1

Ubuntu 26.04 ships GNU Wget 1.25.0 as wget, with wget2 as a separate package. Note the major version, because on some distros the same command name runs wget2 instead:

GNU Wget 1.25.0 built on linux-gnu.

Downloading log-01.gz a second time shows the numbering, and -nc (no clobber) is the flag that stops it. The screenshot runs both against the same URL, and you can see wget announce that it skipped the file instead of quietly creating log-01.gz.2:

wget --version on Ubuntu 26.04 showing GNU Wget 1.25.0, a rerun saving log-01.gz.1 and -nc skipping the existing file

Pick the flag by what you want the second run to do:

  • -nc: keep the existing file, never download again
  • -N: download only when the server copy is newer
  • -O name: always write to that exact name, replacing it

For a nightly sync, -N is usually what you meant. On the second run it sent If-Modified-Since, nginx answered 304, and wget skipped the transfer.

wget -N http://web01/files/log-10.gz

Read the tail of the output, where the 304 tells you nothing was transferred:

HTTP request sent, awaiting response... 304 Not Modified
File ‘log-10.gz’ not modified on server. Omitting download.

-O has its own trap. Give it two URLs and it concatenates both bodies into that one file, which the lab confirmed with two HTML pages landing in a single 333-byte file, so keep it to single downloads. For pipes, wget -qO- URL | grep ... sends the body to stdout and keeps wget’s messages out of your stream.

Resume trusts the bytes already on disk

wget -c reads the size of your partial file, sends Range: bytes=N-, and appends whatever comes back. That’s the whole mechanism. It works well for a large file that simply got cut off, which is the case below, where a 64 MB backup was interrupted after 4 seconds by timeout and then resumed.

wget -c http://web01/files/backup-2026-11.tar.gz

Look for 206 Partial Content and the “remaining” figure on the Length line. Those two prove the server honoured the range, since a server that ignored it would answer 200 and send the whole file. Running -c again on the finished file gets a 416 and a clean “nothing to do”, so it’s safe to leave -c in a retry loop:

wget -c resuming an interrupted 64 MB download with 206 Partial Content, then 416 when the file is complete

Both sha256 sums matched the original on the server, so in this case the resume was sound. What happens when the file on the server changes between your two attempts? The next test kept the first 2 MB of log-06.gz and replaced the server copy with new content of the same size. Then wget -c ran, printed a normal success line and exited 0, yet the checksums no longer match.

wget -c exits 0 after resuming a file that changed on the server, and sha256sum shows the local copy does not match

What you have on disk now is the first half of the old file joined to the second half of the new one. Nothing in wget’s output says so, which is why a resumed download of anything rebuilt in place (nightly dumps, “latest” ISOs, rolling tarballs) needs a checksum step after it. The opposite failure is noisier but still easy to miss. Against Python’s http.server, which ignores Range headers, wget -c got 200 OK instead of 206 and quietly fetched the whole 4 MB file again from byte zero.

Before you trust a resumed file, check these in order.

  1. The response says 206 Partial Content, not 200 OK
  2. The Length line shows a “remaining” figure
  3. The checksum matches the publisher’s SHA256SUMS

If the publisher ships no checksum file, delete the partial file and start over whenever the source could have changed. It costs you a full download, but it cannot hand you a silently broken archive.

Rate limits and quotas bend

--limit-rate works by sleeping after network reads that came in too fast, so it holds an average rather than a hard ceiling. Over a whole file you can rely on that average. A 4 MiB file pulled with --limit-rate=200k took 20.48 seconds, which is 200 KiB/s almost exactly. The test pulled from a plain Python http.server on port 8082 rather than nginx, so no server-side throttle was mixed in.

/usr/bin/time -f "elapsed %e s" wget -nv --limit-rate=200k http://127.0.0.1:8082/log-05.gz -O rate.gz

Timing came back at the expected value.

2026-11-08 04:15:17 URL:http://127.0.0.1:8082/log-05.gz [4194304/4194304] -> "rate.gz" [1]
elapsed 20.48 s

GNU’s manual warns that the balance takes time to settle, so very small files may finish faster than the limit suggests. Treat the suffixes as binary, with k meaning 1024 bytes and m 1024 KB, which is why 4194304 bytes at 200k lands on 20.48 seconds rather than 21.

-Q is the flag people misread most. It caps how much a recursive or list run will start, but it never cuts a file in progress. With -Q 9m on a directory holding a 64 MB backup, wget fetched the whole backup, then stopped:

wget -r -l1 -nd -np -nv --wait=1 --random-wait -Q 9m -A "*.gz" -P q http://web01/files/

Sixty-four megabytes went through on a 9 MB quota, and the EXCEEDED line only appears afterwards. That ordering is the point to remember, because the quota is checked between files and never inside one:

Total wall clock time: 1m 5s
Downloaded: 2 files, 64M in 1m 3s (1.01 MB/s)
Download quota of 9.0M EXCEEDED!

If you need a hard stop on bytes, put the limit somewhere that can enforce it.

  • A timeout around the whole command
  • A size check on the server’s listing before the run
  • A disk quota on the account that runs wget

Keep -Q for what it does well, which is stopping a long list from starting yet another file once it has pulled enough.

Retries skip the errors you expect

Twenty tries by default sounds generous, yet it does not cover the failures your scripts actually hit. The man page says fatal errors such as “connection refused” and 404 are not retried, and in practice an HTTP 503 from an overloaded backend falls in the same bucket. Each failure below was triggered with no extra flags.

FailureDefault behaviourExitFlag that retries it
HTTP 503Gives up at once8--retry-on-http-error=503
HTTP 404Gives up at once8None, and it shouldn’t
Connection refusedGives up at once4--retry-connrefused
Connect timeoutRetries up to --tries4Already retried

The /flaky endpoint on the lab server answers 503 twice, then 200, with one counter shared by every request. Without help, wget stopped on the first 503 with exit 8. Run straight after it, the flagged command met the second 503, retried, and succeeded on its second try:

wget --tries=5 --waitretry=2 --retry-on-http-error=503 http://web01/flaky -O status.json

In the capture, the first run is the default behaviour and the second is the same URL with the flag.

wget exits 8 on a 503 by default, then retries and succeeds with --retry-on-http-error=503

--waitretry sets a ceiling, not a fixed pause. wget waits 1 second after the first failure, 2 after the second, and so on up to the number you give. Here --waitretry=2 produced a single 1-second gap and the whole run took 1.00 s. Add 429 to the list (--retry-on-http-error=429,503) when you call rate-limited APIs.

Connection refused is the other common one, typically a service that’s still starting after a deploy. A health probe that waits for it looks like this:

wget -nv --tries=3 --waitretry=1 --retry-connrefused http://127.0.0.1:9999/health

Nothing listened on that port, so all three tries failed within 2 seconds and the exit code was 4:

failed: Connection refused.
failed: Connection refused.
failed: Connection refused.

Without --retry-connrefused the same command prints one line and quits. For an unreachable address, --timeout=3 --tries=2 took 7 seconds in the lab, which is two 3-second connect timeouts plus the 1-second backoff between them. Any job you leave unattended should carry three flags, because the default read timeout alone is 900 seconds:

  • --timeout= sized to the slowest healthy response
  • --tries= with a small number, not the default 20
  • --retry-on-http-error=429,503 for busy backends

Add --retry-connrefused only where a refused port really means “still starting”, such as a probe after a deploy. Everywhere else a refused connection is an answer you want to hear quickly.

Passwords on the command line are public

A protected URL without credentials fails with exit 6 and “Username/Password Authentication Failed.” The quick fix is --user and --password, and it works:

wget -nv --user=deploy --password="S3cret-lab-pass" http://web01/private/report.csv

wget picks Basic auth from the server’s challenge and saves the file:

Authentication selected: Basic realm="web01 private"
2026-11-08 04:18:37 URL:http://web01/private/report.csv [14/14] -> "report.csv" [1]

While that download runs, though, any user on the box can read your password from the process list. A throttled download with the same flags showed it in full.

ps -o pid=,args= -C wget

The argument list holds the secret in plain text:

   2856 wget -q --limit-rate=100k --user=deploy --password=S3cret-lab-pass http://web01/files/log-07.gz -O /dev/null

Your shell history keeps a copy too. Use one of these instead, depending on who runs the job:

  • Interactive: --user=deploy --ask-password
  • Unattended: a ~/.netrc with mode 600
  • Per-user default: user and password in ~/.wgetrc, also mode 600

A netrc file needs three keywords per host. Create it with a restrictive mode before the password goes in, so it is never readable by other users even for a moment.

touch ~/.netrc && chmod 600 ~/.netrc
printf "machine web01\nlogin deploy\npassword S3cret-lab-pass\n" >> ~/.netrc

With the file in place, a plain wget authenticates on its own, and nothing sensitive shows in ps:

wget -nv http://web01/private/report.csv -O r3.csv

You get the same result as the command-line version.

Authentication selected: Basic realm="web01 private"
2026-11-08 04:18:37 URL:http://web01/private/report.csv [14/14] -> "r3.csv" [1]

Basic auth sends the password base64-encoded, not encrypted, so over plain HTTP anyone on the path reads it. Keep authenticated downloads on HTTPS, which the TLS section below covers.

Headers and bodies go out as written

wget is not an API client, but it sends custom headers and simple POST bodies well enough for webhooks and health checks. The lab’s /echo path is nginx proxying to a small local echo app that returns whatever it received (which is why it reports its own Host), so you can see exactly what left the machine:

wget -qO- --header="X-Trace-Id: 4f9a2c" --header="Accept: application/json" --user-agent="probe-check/1.0" http://web01/echo

Both headers arrived, and your user agent replaced the default one.

{
  "method": "GET",
  "headers": {
    "Host": "127.0.0.1:8081",
    "Connection": "close",
    "User-Agent": "probe-check/1.0",
    "Accept": "application/json",
    "Accept-Encoding": "identity",
    "X-Trace-Id": "4f9a2c"
  }
}

Without --user-agent, wget announces itself as Wget/1.25.0, which some CDNs and WAFs block outright. If a URL works in a browser and returns 403 to wget, the agent string is the first thing to change. For a POST, set the content type yourself, because wget defaults to form encoding:

wget -qO- --header="Content-Type: application/json" --post-data='{"host":"web01","state":"drain"}' http://web01/echo

Every byte of the body arrived, along with the JSON content type.

{
  "method": "POST",
  "content_type": "application/json",
  "body": "{\"host\":\"web01\",\"state\":\"drain\"}"
}

--post-file=body.json does the same from a file, trailing newline included. To see response headers without saving anything, combine -S with --spider:

wget -S --spider http://web01/site/index.html

In the indented block you see the raw response. Accept-Ranges: bytes is the line that tells you -c will work against this server:

  HTTP/1.1 200 OK
  Server: nginx/1.28.3 (Ubuntu)
  Date: Sun, 08 Nov 2026 04:18:49 GMT
  Content-Type: text/html
  Content-Length: 372
  Last-Modified: Sun, 08 Nov 2026 04:13:05 GMT
  Connection: keep-alive
  ETag: "6aeff6d1-174"
  Accept-Ranges: bytes
Length: 372 [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.

Run that check before any long download you might need to resume. Switch to curl once a job needs any of these:

  • Methods beyond GET and POST as routine work
  • Error bodies printed without extra flags
  • Per-request timing such as time to first byte
  • Multipart form uploads

The comparison near the end shows where the line between the two tools falls.

Background jobs log to a file

wget -b detaches from the terminal, prints its PID and writes all progress to wget-log in the current directory. wget starts its own session, so the download keeps going after you log out, which is the reason to use it over a plain &. The exception is a host where systemd-logind has KillUserProcesses=yes, which kills everything a user started at logout:

wget -b --limit-rate=2m http://web01/files/backup-2026-11.tar.gz

wget returns immediately with the PID you’ll need to stop it.

Continuing in background, pid 2924.
Output will be written to ‘wget-log’.

Start a second background job in the same directory and wget writes to wget-log.1, the same numbering it uses for downloads. Two jobs into wget-log and wget-log.1 are easy to mix up, so name the log yourself with -o when more than one job runs:

wget -b -o backup.log http://web01/files/log-08.gz

Three commands cover the rest of a background job’s life:

  • tail -f wget-log follows the progress
  • pgrep -a wget lists running jobs with arguments
  • kill <pid> stops one and keeps the partial file

A killed job leaves its partial file on disk, ready for -c, with every caveat from the resume section. Use -a instead of -o when several runs should share one log, since -o overwrites it each time.

Input lists take no comments

wget -i urls.txt downloads every URL in the file, one per line. The file format is literal, though: a line starting with # is not a comment. It is a URL that wget cannot parse. The test list below holds two good files, a comment, a URL that doesn’t exist and one more good file:

wget -nv -i urls.txt

wget turned the comment into http://# comment line, skipped the 404, finished the rest and exited 8:

wget -i urls.txt treating a comment line as an invalid URL, skipping a 404 and exiting 8

Your scripts should take three facts from that output, and all of them point the same way, toward the exit code:

  • FINISHED counts only the 3 files that worked
  • One bad line never stops the batch
  • Exit 8 is the only sign anything failed

Carrying on past a bad line is good for a large mirror and bad for a deploy step that needs every file, so a deploy should check $? and stop. If you keep comments in the list, strip them on the way in:

grep -v '^#' urls.txt | wget -nv -i -

When the list holds bare file names, -B supplies the base URL. This pulled log-04.gz and log-05.gz into batch/:

wget -nv -B http://web01/files/ -i names.txt -P batch/

Both names resolved against the base URL.

2026-11-08 04:19:40 URL:http://web01/files/log-04.gz [4194304/4194304] -> "batch/log-04.gz" [1]
2026-11-08 04:19:43 URL:http://web01/files/log-05.gz [4194304/4194304] -> "batch/log-05.gz" [1]
FINISHED --2026-11-08 04:19:43--
Total wall clock time: 6.0s
Downloaded: 2 files, 8.0M in 6.0s (1.33 MB/s)

wget 1.x works through the list one file at a time, which is why the ten-file list later in this sheet takes 30 seconds. wget2 changes that.

--spider requests each URL without saving it. On one URL it is an existence check that exits 0 or 8. Add -r and it crawls the site and reports every dead link at the end, which makes it a free link checker for documentation sites:

wget --spider -r -l 3 --no-parent -nd -nv -o spider.log http://web01/site/

At the bottom of the log you’ll find the summary. The test site links to team.html and old-release-notes.html, neither of which exists.

wget --spider -r link check reporting Found 2 broken links and exit status 8

--no-parent decides what gets checked. The first run left it off, wandered out of /site/ and reported 3 broken links, the third being the server root http://web01/, which had nothing to do with the docs. Set the scope deliberately:

  • -np: never climb above the start directory
  • -l 3: stop three links deep
  • -nd: create no local directories
  • -o spider.log: keep the report for grep

Any broken link makes the exit code 8, so the command drops straight into CI as a gate. External links are not followed unless you add -H, and on a real site that quickly turns into crawling the internet. Keep it off unless you also limit hosts with -D.

Mirrors exit 8 on one missing page

For an offline copy, --mirror alone is not enough. It turns on recursion with infinite depth and timestamping, but your pages still point at the live server and miss their CSS and images. Use the full set of flags.

wget --mirror --convert-links --adjust-extension --page-requisites --no-parent -nv -o mirror.log http://web01/site/

What each one adds, in the order wget applies them:

  1. --mirror: recursion, infinite depth, -N
  2. --no-parent: stay under /site/
  3. --page-requisites: fetch CSS and images
  4. --adjust-extension: add .html where missing
  5. --convert-links: rewrite links to local paths at the end

Seven files landed, and the links inside docs/install.html were rewritten to relative paths like ../css/site.css, so the copy opens from disk. Even so, wget exited 8, because team.html returned 404. A script that treats any non-zero exit as “mirror failed” will throw away a perfectly usable copy, so check mirror.log for ERROR lines and decide from those.

For one directory of files rather than a site, -A and -R filter by name. With -r -l1 -nd -np -A "log-0[1-3].gz", wget fetched exactly three files from the autoindex listing. It downloaded the listing page to find them, then deleted it because it did not match the pattern.

wget also honours robots.txt during recursion. On a server you run, -e robots=off turns that off. On someone else’s server, leave it on and add --wait=1 --random-wait so your crawl doesn’t look like an attack.

TLS failures exit with code 5

An internal server with a certificate from a private CA fails verification with exit 5. The fix is to trust that CA, not to switch verification off. The lab put web01 behind a certificate signed by a throwaway “Lab CA”:

wget -nv --ca-certificate=lab-ca.pem https://web01/site/index.html

Without the CA, the first command in the capture fails. With it, the second passes.

wget certificate not trusted error with exit 5, fixed with --ca-certificate=lab-ca.pem

--no-check-certificate also gets the file. The same two lines print as WARNING instead of ERROR, and the exit code becomes 0, so a script that only checks $? never sees them. Pick the fix by scope:

  1. System store with update-ca-certificates for every tool
  2. --ca-certificate= for one command or one script
  3. --no-check-certificate only on a throwaway lab box

When you don’t know which CA signed a server’s certificate, the OpenSSL cheat sheet covers inspecting the chain with s_client.

Wget2 is a different program

On Fedora 40 and later, wget is wget2: the Fedora change swapped the package and documents FTP and WARC as the gaps. Ubuntu 26.04 and Debian still ship wget 1.x as wget and wget2 as a separate wget2 package, so the same script can run two different downloaders depending on the distro. Versions differ too: Ubuntu 26.04’s wget2 is 2.2.0, which is what this lab measured, while Fedora 43 to 45 carry 2.3.0, and Fedora still packages wget1-wget if you want the old binary back as wget. The DNF5 cheat sheet shows how to check which package provides a command on Fedora.

Parallelism is the headline difference, since wget2 downloads 5 files at once by default. The lab server limits each connection to 1 MB/s, and you can see what that did to ten 4 MB files.

wget vs wget2 timing: ten 4 MB files in 30.04 s with wget, 6.05 s with wget2 and 3.02 s with --max-threads=10

That’s 30.04 seconds for wget, 6.05 for wget2 and 3.02 with --max-threads=10. Read those numbers for what they measure, a server that throttles per connection, which mirrors and package hosts commonly do. When your own link is the bottleneck, ten threads share the same bandwidth and the gain disappears. Everything else was checked flag by flag against the same server.

Behaviourwget 1.25.0wget2 2.2.0 (Ubuntu)
-c resume206, file identical206, file identical
-b backgroundLogs to wget-logLogs to wget-log
--limit-rate=200k on 4 MiB20.48 s20.47 s
--retry-on-http-error=503RetriesRetries
Auth failure / TLS failureExit 6 / exit 5Exit 6 / exit 5
--spider -r report“Found 2 broken links.” listNo summary list, exit 8
ftp:// URLSupported“Failed to parse URI”, exit 0
HTTP/2NoOffers h2 via ALPN

FTP is the dangerous row. wget2 2.2.0 refuses the URL, prints Nothing to do - goodbye and exits 0, so a script that switches from wget to wget2 on Ubuntu or Debian reports success while downloading nothing. The wget2 2.3.0 release notes list “Set exit code to 1 for no-op invocations”, so on current Fedora the same FTP URL still fails, but with exit 1 that $? catches. Link checkers need the spider row: the exit code still works, but the “Found N broken links” block you’d grep for isn’t there, so grep for HTTP ERROR response instead. With -d, wget2 logged ALPN: Server accepted protocol 'h2' against Cloudflare’s site, while gnu.org accepted only http/1.1.

Before you let a wget script run on Fedora, check it for these:

  • Any ftp:// URL, which wget2 cannot fetch
  • Parsing of the spider summary
  • WARC options such as --warc-file

Upstream keeps the full list of wget and wget2 differences on the wget2 wiki, and it’s worth a read before a fleet with mixed distros shares one download script.

Wget saves files, curl talks to APIs

Both tools download a URL, so which one should your script use? Pick by what happens after the first request. wget writes files, follows links and recurses, while curl prints to stdout and gives you full control over one request. The curl cheat sheet covers the request side in the same tested format.

Jobwgetcurl
Default outputSaves a filePrints to stdout
Mirror or crawl a site--mirror, --spider -rNo recursion
Resume-c-C -
Methods and bodiesGET, POST, --methodAny method, multipart -F
Error body on 4xx/5xxDiscarded unless --content-on-errorPrinted by default

In practice that means wget for downloads, mirrors and link checks, and curl for anything that inspects responses. On a minimal container image you often have room for only one, and the apt cheat sheet shows the --no-install-recommends install that keeps that layer small.

Exit codes decide what your script does

Every trap above surfaced through the exit code, not the text output. This is the table from the GNU Wget manual, with the run in this lab that produced each code:

ExitMeaningSeen in this lab
0No problemsIncludes -c on a changed file and --no-check-certificate
1Generic errorNot triggered
2Parse error in options, .wgetrc or .netrcNot triggered
3File I/O errorNot triggered
4Network failureConnection refused, connect timeout
5SSL verification failurePrivate CA without --ca-certificate
6Authentication failureProtected URL without credentials
7Protocol errorNot triggered
8Server error response503 without retry flag, 404 in a list, mirror or spider

When several kinds of failure hit one run, the lower-numbered code wins (0 and 1 aside), so a list with one refused connection and ten 404s exits 4, not 8. Map the codes to actions in your script:

  • 4: retry later, the network or service is down
  • 5 or 6: fix trust or credentials, retrying won’t help
  • 8: read the log, some URLs worked
  • 0 after -c: verify the checksum anyway

Exit 0 only says the transfer finished. Whether the bytes are the ones you wanted is a question for sha256sum, never for wget, because every check wget makes happens at the HTTP layer and none of them looks at content. That is the one rule behind most of this sheet: -c on a changed file, --no-check-certificate and wget2 2.2.0’s FTP refusal all exit 0 without proving you got what you asked for.

The rest of the printable set, including the SSH, Docker and OpenSSL sheets, is on the Linux and DevOps cheat sheets page.

Keep reading

Claude Code Cheat Sheet: Commands, Shortcuts and Flags (PDF) AI Claude Code Cheat Sheet: Commands, Shortcuts and Flags (PDF) OpenAI Codex CLI Cheat Sheet: Shortcuts, Commands, Flags (PDF) AI OpenAI Codex CLI Cheat Sheet: Shortcuts, Commands, Flags (PDF) macOS Keyboard Shortcuts Cheat Sheet (Golden Gate and Tahoe) Cheat Sheets macOS Keyboard Shortcuts Cheat Sheet (Golden Gate and Tahoe) uv Cheat Sheet: Python Package Manager Commands (PDF) Cheat Sheets uv Cheat Sheet: Python Package Manager Commands (PDF) DNF Cheat Sheet: dnf5 on Fedora, dnf on Rocky Linux 10 (PDF) Cheat Sheets DNF Cheat Sheet: dnf5 on Fedora, dnf on Rocky Linux 10 (PDF) nmcli Cheat Sheet: NetworkManager Commands with Examples (PDF) Cheat Sheets nmcli Cheat Sheet: NetworkManager Commands with Examples (PDF)

Leave a Comment

Press ESC to close