wget Command in Linux with Examples

Discover 30 practical wget command examples for Linux. Download files, mirror websites, and automate tasks effortlessly in your terminal.

Last updatedAuthorJoshua JamesRead time11 minGuide typeLinux Commands

Large downloads, flaky SSH sessions, and offline documentation mirrors are where the wget command earns its keep. It retrieves files over HTTP, HTTPS, FTP, and FTPS without a browser, then gives you control over retries, bandwidth limits, authentication, timestamps, and logging.

These wget examples move from single-file downloads to recursive mirrors, cookie-based authentication, API requests, and cron-friendly logs. Pair them with our curl command examples when the job shifts from retrieving files to inspecting APIs, sending complex requests, or debugging HTTP responses.

Understand the wget Command

If you are new to wget, think of it as a command-line download manager that fetches files from web servers. The basic syntax is straightforward:

wget [options] URL

Breaking this down:

  • wget: The command itself, which stands for “web get”.
  • options: Optional flags that modify wget’s behavior. For example, -c resumes interrupted downloads, -O saves with a custom filename, or -b runs in the background. You can combine multiple options in a single command.
  • URL: The web address of the file or page you want to download. This can be an HTTP, HTTPS, FTP, or FTPS link.

At its simplest, wget https://example.com/file.zip downloads file.zip to your current directory. The real power comes from options that let you resume broken transfers, mirror entire sites, throttle bandwidth, or automate downloads in scripts.

For exhaustive option details, use man wget locally or the official GNU Wget manual online. The examples focus on command shapes you can adapt without reading every manual entry first.

This quick reference groups common options by task. Treat it as a map for the examples rather than a list to memorize.

TaskCommand PatternWhat It Does
Single downloads-O, -P, -c, --content-dispositionRename files, choose directories, resume transfers, or use server-suggested names
Website mirroring--mirror, -r, -l, -A, -RDownload entire sites, control crawl depth, or accept and reject file types
Automation-b, --tries, --append-output, --quietRun in the background, retry failures, and keep logs useful for scripts
Authentication--user, --ask-password, --load-cookies, --save-cookiesHandle login prompts and session cookies without hardcoding passwords
Networking--limit-rate, --wait, -4, -e http_proxy=...Limit bandwidth, add delays, force IPv4 or IPv6, or route through a proxy

Install the wget Command on Major Linux Distributions

Most Linux distributions either ship GNU Wget or make it available from the default repositories. Minimal containers and Alpine images may expose BusyBox wget instead, which handles basic downloads but lacks many GNU Wget options used later. Verify which implementation your system uses:

wget --version
GNU Wget 1.x.x built on linux-gnu.

GNU Wget prints a version banner. If you see BusyBox usage output or an unrecognized option instead, install the full GNU Wget package before using GNU-only options from later examples.

If the shell cannot find wget, install the package that matches your distribution family.

Ubuntu and Debian-based distributions

sudo apt install wget

Fedora, RHEL, Rocky Linux, and AlmaLinux

sudo dnf install wget

Arch Linux and Manjaro

sudo pacman -S wget

openSUSE

sudo zypper install wget

Alpine Linux

apk add wget

Run the Alpine command as root, or with sudo or doas if your system has one configured. The Alpine package named wget installs GNU Wget; the BusyBox applet documents only a smaller option set such as -c, -s, -q, -O, --header, -Y, -P, and -U.

Gentoo Linux

sudo emerge --ask net-misc/wget

Void Linux

sudo xbps-install -S wget

Use the repository package for normal downloads, mirrors, and automation. Compile from the GNU Wget source only when you have a specific patch or build option to validate; it is not the usual fix for ordinary TLS or repository-version concerns.

Practical wget Command Examples

These examples cover day-to-day tasks along with automation-friendly tricks. Adapt the URLs and file paths to match your environment.

Example 1: Download a Single File

Start with the most basic use case: downloading a single file. wget saves it using the filename provided by the server, placing it in your current working directory.

wget https://downloads.example.com/images/debian.iso

After the download completes, the file appears in whichever directory you were in when you ran the command. Verify its integrity with sha256sum before using it.

sha256sum debian.iso
1f2d3c4b5a6e7890cdef1234567890abcdef1234567890cdef1234567890ab  debian.iso

Example 2: Run Downloads in the Background

When downloading large files, you may want to continue using your terminal for other tasks. The -b flag runs wget in the background, freeing up your command line immediately.

wget -b https://downloads.example.com/archives/app.tar.gz
Continuing in background, pid 18593.
Output will be written to 'wget-log'.

wget writes progress updates to a file named wget-log in your current directory. Monitor the download with tail -f wget-log (see our tail command examples for more options). This approach is especially useful when working on remote servers via SSH, or within terminal multiplexers like tmux or screen.

Example 3: Limit Download Bandwidth

To prevent wget from consuming your entire network connection, use --limit-rate to throttle the download speed. This keeps your connection responsive for other applications and users.

wget --limit-rate=500k https://downloads.example.com/releases/backup.tar.gz

The rate limit accepts values with suffixes: k for kilobytes per second or m for megabytes per second. In this example, wget caps the download at 500 KB/s, leaving bandwidth available for browsing or other transfers.

For speed checks, use a file you control or an ISP or mirror that intentionally publishes test downloads. Random “large test file” URLs disappear, change size, or create unfair load for someone else’s server.

Example 4: Save with a Custom Filename

By default, wget uses the filename from the URL. When you need a different name, for instance to maintain consistent naming across versioned releases, use the -O option (that’s a capital letter O, not zero).

wget -O latest.tar.gz https://downloads.example.com/releases/app-2025.1.tar.gz

This downloads app-2025.1.tar.gz but saves it as latest.tar.gz. Scripts that always extract “latest.tar.gz” work without modification when a new version arrives.

Example 5: Save into a Specific Directory

Instead of navigating to a target directory before downloading, use -P (prefix) to specify where wget should save the file.

mkdir -p ~/Downloads/isos
wget -P ~/Downloads/isos https://downloads.example.com/images/fedora.iso

The file lands in ~/Downloads/isos/ regardless of your current working directory. The mkdir command makes the example script-friendly, especially when you later switch from -P to an -O path/file target that expects the parent directory to already exist.

Example 6: Resume an Interrupted Download

Network hiccups or dropped SSH connections can interrupt large downloads. Instead of starting over, use the -c flag to continue from where the transfer stopped.

wget -c https://downloads.example.com/weekly/backup.tar.gz

wget requests only the remaining bytes from the server, saving time and bandwidth. The server must support range requests (most do), otherwise wget falls back to re-downloading the entire file.

Example 7: Skip Unchanged Files with Timestamping

Use -N to download a file only when the remote copy is newer than your local version.

wget -N https://updates.example.com/daily-report.csv

This is ideal for cron jobs that should grab reports once per day without overwriting unchanged files.

Example 8: Honor Server Filenames

APIs often redirect download links. The --content-disposition flag asks wget to use the filename suggested by the server.

wget --content-disposition https://downloads.example.com/get?id=12345

It prevents generic names like get?id=12345 and keeps your artifacts labeled correctly. The GNU wget man page marks --content-disposition as experimental, so verify filenames after download when using it in automation.

Example 9: Download URLs from a List

When you have multiple files to download, save their URLs in a plain text file (one URL per line) and feed it to wget with the -i option.

wget -i ~/wget/url-list.txt

wget processes each URL sequentially, downloading all files in the order they appear. This is particularly handy for batch updates, mirror synchronization, or deploying multiple packages in configuration management systems.

Example 10: Mirror a Site for Offline Use

wget can download entire websites for offline browsing, which is useful for documentation portals, internal wikis, or knowledge bases. The --mirror option combines several features to create a complete local copy.

wget --mirror --convert-links --adjust-extension --page-requisites --no-parent https://docs.example.com/

Each flag in this command plays a role:

  • --mirror: Enables recursive downloading with timestamping to keep copies current.
  • --convert-links: Rewrites links so pages work when opened locally.
  • --adjust-extension: Adds .html where needed so browsers render files correctly.
  • --page-requisites: Pulls stylesheets, images, and scripts that pages reference.
  • --no-parent: Stops wget from crawling above the starting directory.

Check the site’s robots.txt file before mirroring to ensure you follow their crawling policies.

Example 11: Mirror a Specific Subdirectory

Limit a mirror to an area you care about while staying on the same host.

wget --mirror --no-parent https://docs.example.com/docs/api/

This starts the crawl inside /docs/api/, and --no-parent keeps wget from climbing above that path. Include the trailing slash so wget treats the URL as a directory hierarchy.

Example 12: Limit Recursion Depth

Set a recursion depth when you want a quick snapshot of near-neighbor pages without crawling an entire site.

wget -r -l 2 -np https://intranet.example.com/news/

-l 2 tells wget to follow links two levels deep, which is often enough for release notes or team dashboards.

Example 13: Download Only Specific File Types

Target PDFs or images from a site without hauling everything else along.

wget -r -np -A 'pdf,epub' https://library.example.com/publications/

The -A list accepts comma-separated extensions, helping you curate download sets for research archives.

Example 14: Reject Unwanted File Types

Skip bloated archives or binaries when you only need HTML and text.

wget -r -R 'zip,tar.gz' https://downloads.example.com/datasets/

Pair rejections with -A filters to zero in on the artifacts that matter.

Example 15: Slow Down to Respect Busy Servers

Throttle requests between pages when mirroring community sites so you do not trigger rate limits.

wget -r --wait=2 --random-wait https://projects.example.org/releases/

--random-wait adds a small variable delay, so repeated requests do not arrive at a perfectly fixed interval.

Advanced wget Command Techniques

Example 16: Detect Broken Links with Spider Mode

Spider mode tells wget to check URLs without actually downloading files. This is perfect for auditing websites to find broken links (404 errors) or testing site structure.

wget --spider -r -l 4 -o wget-spider.log https://docs.example.com/

The --spider flag skips downloads and only requests headers. wget logs all HTTP responses to wget-spider.log. After the scan completes, search the log for “404” or “broken link” messages with grep:

grep '404' wget-spider.log

Example 17: Inspect Headers Without Downloading

Combine spider mode with --server-response to confirm metadata such as Last-Modified before pulling a huge file.

wget --spider --server-response https://downloads.example.com/images/server.img

The command prints response headers and exits, so you can spot stale mirrors or unexpected redirects.

Example 18: Authenticate with Basic Credentials

Hit intranet portals or staging servers that require HTTP basic auth without placing the password in your shell history.

wget --http-user=buildbot --ask-password https://intranet.example.com/builds/report.html

wget prompts for the password and keeps it out of the visible command line. Avoid --password=... and password-bearing URLs on shared systems because other users can inspect process arguments.

Example 19: Use a Protected netrc File

For repeated non-interactive downloads, let wget read credentials from ~/.netrc after you restrict the file permissions.

machine vault.example.com
  login admin
  password replace-this-password

After saving the entry, restrict the file and download the protected resource:

chmod 600 ~/.netrc
wget https://vault.example.com/exports/config.yaml

The ~/.netrc file stores plain-text credentials, so use it only for accounts where that storage model is acceptable. The chmod command guide explains mode 600 if you need the permission breakdown. Remove short-lived credentials after the job finishes.

Example 20: Reuse Session Cookies

Some dashboards gate downloads behind login flows. Import cookies captured from a browser session.

wget --load-cookies cookies.txt https://portal.example.com/reports/monthly.pdf

Export cookies in Netscape format (browser extensions such as cookies.txt for Firefox or Chrome can generate this file) and keep the file secure, since it grants the same access as your login.

Example 21: Capture Cookies for Later Requests

Use --save-cookies to stash session data during a scripted login, then call wget again with --load-cookies. Keep form credentials out of process arguments by writing the temporary POST body to a protected file.

( umask 077
  printf 'user=admin&password=%s' "$PORTAL_PASS" > portal-login.txt
)
wget --save-cookies=session.txt --keep-session-cookies \
  --post-file=portal-login.txt \
  https://portal.example.com/login

The subshell applies restrictive permissions only while creating portal-login.txt, and wget captures the authenticated session in session.txt. Adjust the POST body for the real form fields, and URL-encode values when the login form requires it.

wget --load-cookies=session.txt \
  https://portal.example.com/reports/monthly.pdf

Follow up with the resource you actually need while reusing the saved cookies. Remove both portal-login.txt and session.txt afterward so credentials do not linger on disk.

Delete only the temporary login body and cookie file created for this workflow. If you reused an existing cookie file, back it up or skip this cleanup.

rm -f portal-login.txt session.txt

Example 22: Send Custom Headers

APIs often use headers for content negotiation, feature flags, or request tracing. Add non-secret headers with --header.

wget --header="Accept: application/json" https://api.example.com/v1/metrics

You can repeat --header for additional values like X-Request-ID. Avoid putting bearer tokens in command-line headers on shared systems because process listings and logs can expose them.

Example 23: Submit Form Data with POST

Push data to an endpoint using --post-data. wget sets the request method to POST automatically.

wget --post-data="name=backup&status=completed" https://hooks.example.com/deploy

Remember that wget is still a download tool; it prints the response body so you can log or inspect success codes.

Example 24: POST JSON from a File

Load structured payloads from disk using --post-file alongside the correct content type header.

wget --header="Content-Type: application/json" --post-file=payload.json https://api.example.com/v1/import

For complex API work, multipart uploads, or detailed response inspection, curl is usually the cleaner tool. Use wget here when the response body is the artifact you want to save.

Example 25: Validate TLS with a Custom CA Bundle

Internal services often use private certificate authorities. Point wget at the correct trust store.

wget --ca-certificate=/etc/pki/internal-ca.pem https://intranet.example.com/dashboard/

This maintains TLS validation instead of disabling checks, which keeps connections protected from man-in-the-middle attacks.

Example 26: Temporarily Skip Certificate Checks

Use --no-check-certificate only during controlled testing when you must reach a host with a broken certificate chain. The flag temporarily bypasses verification so you can confirm if TLS is the culprit.

Follow up by fixing the certificate or switching to a trusted CA bundle; leaving this flag in production is risky.

wget --no-check-certificate https://staging.example.com/healthz

Example 27: Route Traffic Through a Proxy

Respect corporate proxies or route around geofenced resources with -e directives.

wget -e use_proxy=yes -e http_proxy=http://proxy.example.com:3128 https://downloads.example.com/tools/cli.tar.gz

Set https_proxy similarly when you need to route encrypted traffic through the proxy as well.

Example 28: Force IPv4 or IPv6

Debug dual-stack issues by telling wget to use IPv4 (-4) or IPv6 (-6) explicitly.

wget -4 https://downloads.example.com/repository/index.html

If the IPv4 path fails while IPv6 works, or vice versa, you know where to focus your troubleshooting.

Example 29: Customize the User-Agent

Some CDNs tune responses based on user agents. Provide a descriptive string that identifies your script or organization.

wget --user-agent="LinuxCapable-Wget/1.0 (+https://linuxcapable.com/)" https://downloads.example.com/assets/theme.css

A clear user agent also helps server owners understand legitimate automation traffic in their logs.

Example 30: Quiet Mode with Persistent Logs

Script-friendly output combines --quiet with --append-output, so logs accumulate across runs.

mkdir -p "$HOME/wget-logs" "$HOME/mirror"
wget --quiet --append-output="$HOME/wget-logs/sync.log" -P "$HOME/mirror" https://mirror.example.com/latest.tar.gz

Check the log during audits without losing earlier entries. For system-wide cron jobs, switch the paths to a service-owned directory and make sure that account can write there before scheduling the command.

Troubleshoot Common wget Errors

wget Command Not Found

If your shell returns this error, wget is not installed or not in your PATH:

bash: wget: command not found

Install wget using the package manager for your distribution as shown in the installation section, then confirm it is available:

wget --version

Unable to Resolve Host Address

If wget cannot look up the server name, you will see:

wget: unable to resolve host address 'downloads.example.com'

This means DNS resolution failed. Confirm your network connection is active and that you can reach a known host:

ping -c 2 1.1.1.1 && nslookup downloads.example.com

If ping reaches the IP address but the nslookup command cannot resolve the domain, check /etc/resolv.conf for a valid nameserver entry or try a public resolver like 1.1.1.1 or 8.8.8.8.

Certificate Verification Failed

HTTPS downloads can fail when the system CA bundle is missing or outdated:

ERROR: The certificate of 'downloads.example.com' is not trusted.
ERROR: The certificate of 'downloads.example.com' doesn't have a known issuer.

Install or update your CA certificates and retry. On Debian and Ubuntu systems:

sudo apt install ca-certificates
sudo update-ca-certificates

On Fedora, RHEL, Rocky Linux, and AlmaLinux systems:

sudo dnf install ca-certificates
sudo update-ca-trust

Verify the fix by retrying the HTTPS download.

403 Forbidden Response

Some servers block requests that use wget’s default user agent:

HTTP request sent, awaiting response... 403 Forbidden
ERROR 403: Forbidden.

Set a descriptive user agent string when the site permits automated downloads:

wget --user-agent="LinuxCapable-Wget/1.0 (+https://linuxcapable.com/)" https://downloads.example.com/file.tar.gz

If the 403 persists, the server may require authentication, block your IP range, or disallow automated clients. Check the site’s access policy or contact the administrator instead of trying to bypass the restriction.

Conclusion

The wget command is now ready for repeatable downloads, resumable transfers, offline mirrors, authenticated sessions, and cron-friendly logging. Keep the official manual nearby for rare options, then switch tools when the task changes: curl fits API debugging, grep and tail fit log review, and nslookup fits DNS diagnosis.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Verify before posting: