CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Networking / wget

wget

Download files reliably

Beginnerhttpdownloadnetwork

wget downloads files over HTTP, HTTPS and FTP and saves them to disk. It follows redirects, retries on failure, resumes partial downloads with -c and can mirror whole sites: ideal for fetching releases and artifacts in scripts and Dockerfiles.

Syntaxwget [-q] [-c] [-O FILE] [-P DIR] [--tries=N] [--timeout=SEC] URL...

Watch it run

You need the new release tarball on a server to install it by hand.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 2
wget https://downloads.devops-lab.io/releases/app-2.14.1.tar.gz

wget narrates each step: DNS, TCP connect, the HTTP status, the size and type, then a progress bar and a final summary. The file is saved under the name at the end of the URL.

Anatomy of a command

$
commandwget

GNU Wget: a non-interactive downloader. It keeps working after you log out.

How it works

wget resolves the host (getaddrinfo, so /etc/hosts and DNS), connects to port 80 or 443, runs TLS with OpenSSL on Ubuntu (verifying the certificate against the system CA store), and sends a GET request. It follows redirects automatically (up to 20), prints the status, the Content-Length and the file it is saving to, and streams the body to disk. If the transfer breaks it retries (20 tries by default for transient errors). With -c it looks at the size of the local file and sends Range: bytes=N-; the server answers 206 Partial Content and wget appends only the missing bytes. If the server ignores ranges, wget starts again from zero. In recursive mode (-r, --mirror) it parses downloaded HTML for links and fetches them too, respecting robots.txt. Exit codes say what failed: 4 network, 5 TLS verification, 6 authentication, 8 an HTTP error such as 404.

Options you'll actually use

-O FILESave as FILE (-O - prints the body to stdout)
-P DIRSave into directory DIR, keeping the remote file name
-cContinue a partial download instead of starting over
-q / -nvQuiet / non-verbose: one line per file
--show-progressShow the progress bar even with -q
--tries=NRetry count (default 20; 0 means forever)
--timeout=SECDNS, connect and read timeout
--spiderCheck the URL exists without downloading it
-SPrint the server's response headers
--header='K: V'Add a request header, for example an auth token
-bGo to background immediately and log to wget-log
-r / --mirrorRecursive download / mirror a site with timestamps
--limit-rate=1mCap bandwidth so a big download doesn't starve the app
--no-check-certificateSkip TLS verification (avoid; only for throwaway tests)

Common mistakes

wget URL in a script, then using the file without checking

On failure wget may leave no file, a partial file, or (with -O) an empty file, and the script carries on.

wget -q -O app.tar.gz URL || exit 1 # or set -e
Running wget twice for the same URL

The second run doesn't overwrite: it saves app.tar.gz.1, and later steps use the old file.

wget -O app.tar.gz URL # or -c to finish a partial one, -N to refresh if newer
--no-check-certificate to get past a TLS error

It disables server authentication; a tampered binary would install silently.

Fix the certificate, or add the internal CA: --ca-certificate=/path/ca.pem
Leaving wget's defaults in CI

20 retries with back-off and long timeouts make a dead mirror look like a hung build for many minutes.

wget --tries=3 --timeout=10 URL

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    There's no internet in the sandbox. Use wget to request http://localhost/ and read wget's messages: did anything answer?

  2. 2

    Request a URL on a closed local port with only 1 try and a 2-second timeout, then print wget's exit code.

  3. 3

    Write the wget command that downloads https://downloads.devops-lab.io/releases/app-2.14.1.tar.gz into /opt/releases, resuming if a partial file is there, quietly but with a progress bar.

Related commands

curlMake HTTP requests and debug APIstarBundle files into an archive and extract themdigQuery DNS and read the full answerssSee listening ports and open connections
PreviouscurlNextssh
Linux / Networking / wget

wget

Download files reliably

Beginnerhttpdownloadnetwork

wget downloads files over HTTP, HTTPS and FTP and saves them to disk. It follows redirects, retries on failure, resumes partial downloads with -c and can mirror whole sites: ideal for fetching releases and artifacts in scripts and Dockerfiles.

Syntaxwget [-q] [-c] [-O FILE] [-P DIR] [--tries=N] [--timeout=SEC] URL...

Watch it run

You need the new release tarball on a server to install it by hand.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 2
wget https://downloads.devops-lab.io/releases/app-2.14.1.tar.gz

wget narrates each step: DNS, TCP connect, the HTTP status, the size and type, then a progress bar and a final summary. The file is saved under the name at the end of the URL.

Anatomy of a command

$
commandwget

GNU Wget: a non-interactive downloader. It keeps working after you log out.

How it works

wget resolves the host (getaddrinfo, so /etc/hosts and DNS), connects to port 80 or 443, runs TLS with OpenSSL on Ubuntu (verifying the certificate against the system CA store), and sends a GET request. It follows redirects automatically (up to 20), prints the status, the Content-Length and the file it is saving to, and streams the body to disk. If the transfer breaks it retries (20 tries by default for transient errors). With -c it looks at the size of the local file and sends Range: bytes=N-; the server answers 206 Partial Content and wget appends only the missing bytes. If the server ignores ranges, wget starts again from zero. In recursive mode (-r, --mirror) it parses downloaded HTML for links and fetches them too, respecting robots.txt. Exit codes say what failed: 4 network, 5 TLS verification, 6 authentication, 8 an HTTP error such as 404.

Options you'll actually use

-O FILESave as FILE (-O - prints the body to stdout)
-P DIRSave into directory DIR, keeping the remote file name
-cContinue a partial download instead of starting over
-q / -nvQuiet / non-verbose: one line per file
--show-progressShow the progress bar even with -q
--tries=NRetry count (default 20; 0 means forever)
--timeout=SECDNS, connect and read timeout
--spiderCheck the URL exists without downloading it
-SPrint the server's response headers
--header='K: V'Add a request header, for example an auth token
-bGo to background immediately and log to wget-log
-r / --mirrorRecursive download / mirror a site with timestamps
--limit-rate=1mCap bandwidth so a big download doesn't starve the app
--no-check-certificateSkip TLS verification (avoid; only for throwaway tests)

Common mistakes

wget URL in a script, then using the file without checking

On failure wget may leave no file, a partial file, or (with -O) an empty file, and the script carries on.

wget -q -O app.tar.gz URL || exit 1 # or set -e
Running wget twice for the same URL

The second run doesn't overwrite: it saves app.tar.gz.1, and later steps use the old file.

wget -O app.tar.gz URL # or -c to finish a partial one, -N to refresh if newer
--no-check-certificate to get past a TLS error

It disables server authentication; a tampered binary would install silently.

Fix the certificate, or add the internal CA: --ca-certificate=/path/ca.pem
Leaving wget's defaults in CI

20 retries with back-off and long timeouts make a dead mirror look like a hung build for many minutes.

wget --tries=3 --timeout=10 URL

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    There's no internet in the sandbox. Use wget to request http://localhost/ and read wget's messages: did anything answer?

  2. 2

    Request a URL on a closed local port with only 1 try and a 2-second timeout, then print wget's exit code.

  3. 3

    Write the wget command that downloads https://downloads.devops-lab.io/releases/app-2.14.1.tar.gz into /opt/releases, resuming if a partial file is there, quietly but with a progress bar.

Related commands

curlMake HTTP requests and debug APIstarBundle files into an archive and extract themdigQuery DNS and read the full answerssSee listening ports and open connections
PreviouscurlNextssh