Use Wget’s directory-prefix option:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

wget -P /path/to/directory https://example.com/file.zip

-P (long form: --directory-prefix) tells Wget where to place the download while it keeps the filename supplied by the server or URL. The GNU Wget 1.25.0 Manual defines this prefix as the top of the retrieval tree; if you omit it, Wget uses the current directory (.). See the GNU Wget manual for the versioned option reference.

Save one file in a chosen directory

Run the command from any directory and replace the destination with an absolute or relative path:

wget -P downloads https://example.com/file.zip

With a relative path, Wget creates the destination beneath your current working directory’s context. With an absolute path, use the complete filesystem location:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

wget -P /var/tmp/releases https://example.com/file.zip

Wget chooses the local filename from the URL or the response. In the examples above, the file is saved as file.zip inside the selected directory. If the URL ends in a query string or redirects, inspect Wget’s final output to confirm the resulting name.

Use the long option when scripts need readability

The equivalent explicit form is:

wget --directory-prefix=/path/to/directory https://example.com/file.zip

The short and long forms perform the same job. Put the directory path after a space with -P, or attach it with an equals sign to the long option.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Download several independent URLs into one directory

Give multiple URLs in one invocation. Wget places each downloaded file beneath the prefix and retains each URL’s filename:

wget -P downloads https://example.com/a.zip https://example.com/b.zip

For a longer list, put one URL per line in a text file and pass it with -i:

wget -P downloads -i urls.txt

Check that every line contains the intended URL. A malformed or inaccessible entry can fail independently of the others, so read the completion messages rather than assuming that one successful transfer means the whole list succeeded.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose -P or -O

These options are not interchangeable:

Need Use What it controls
Choose a destination directory and let Wget retain each file’s name -P DIR or --directory-prefix=DIR The directory at the top of the local retrieval tree
Choose one exact output pathname -O FILE The output file itself, including its name and extension

For a single explicitly named file:

wget -O downloads/archive.zip https://example.com/file.zip

Use -O when the output is one file and your script needs a predictable name. Do not use it as a substitute for -P in a multi-file job. The GNU manual warns that with recursive (-r) or page-requisite (-p) downloads, directing output to -O sends all retrieved content into that named output file, which is not a usable directory tree.

Download a bounded directory tree

For a site area containing linked files, combine recursion with an explicit depth and a parent-directory guard:

wget -r -l 1 -np -P downloads https://example.com/files/

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. -r / --recursive: follow links recursively.
  2. -l 1 / --level=1: limit traversal to one link level. Wget documents a default maximum depth of five when recursion is enabled; set the level explicitly when you need a predictable scope.
  3. -np / --no-parent: prevent traversal from ascending above the starting directory.
  4. -P downloads: place the resulting retrieval tree beneath the local downloads directory.

This command is a boundary, not a promise that every file under the URL will be found. Recursive Wget follows links exposed in HTML and CSS. If the server does not publish a browsable directory listing or a link to a file, Wget has no link to follow. Keep the starting URL narrow and review the output list.

Understand the depth value

-l 0 means infinite recursion, not “no recursion.” Infinite depth can continue far beyond the intended area, so use a finite value for routine jobs. A level of one is a common starting point for files linked directly from a directory page; increase it only when the page structure requires another level.

Save a page and its referenced resources

To retrieve one page together with required images, stylesheets, and other page requisites, use -p (long form: --page-requisites):

wget -p -P downloads https://example.com/page.html

Do not pair this all-content operation with -O; the manual documents the same single-output-file problem for page-requisite downloads. Use a directory prefix so each resource can be written into the local tree.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Control the local directory layout

Recursive retrieval normally mirrors the remote structure. The following options change separate parts of that layout:

Option Effect Example
-P DIR Places the entire retrieval tree below DIR. wget -r -P mirror URL
-nd / --no-directories Disables creation of the remote directory hierarchy, putting retrieved files in one local level. wget -r -nd -P flat URL
-nH / --no-host-directories Stops Wget from adding a directory named for the remote host. wget -r -nH -P mirror URL

Because these switches affect different layers, you can combine them. For example:

wget -r -l 1 -np -nH -P downloads https://example.com/files/

Use -nd only when flattening is safe. Two remote files with the same basename can collide when the hierarchy is removed; retaining the tree is safer for archives and page resources.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Practical command patterns

Absolute destination and preserved filename

wget --directory-prefix=/home/alex/downloads https://downloads.example.org/tool.tar.gz

Explicit filename for one artifact

wget -O /home/alex/downloads/tool-latest.tar.gz https://downloads.example.org/tool.tar.gz

Several files from a URL list

wget -P /home/alex/downloads -i urls.txt

One-level collection without parent traversal

wget -r -l 1 -np -P /home/alex/downloads https://example.org/files/

Page plus required assets

wget -p -P site-copy https://example.org/docs/start.html

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

After each run, inspect the path Wget prints and list the destination directory. This catches a relative-path mistake or an unexpected remote filename before a later script consumes the file.

Performance, scope and resource safety

Recursive jobs can consume local disk space, bandwidth, memory and CPU, and can place load on the remote server. The GNU Wget recursive-download guidance recommends keeping the scope and depth narrow and considering -w to add a delay between accesses.

  • Start with one URL and a small -l value.
  • Use -np whenever the starting URL represents a subdirectory.
  • Choose a destination with enough free space before mirroring.
  • Add a wait interval for broad or repeated retrievals, for example -w 2 for a two-second delay between accesses.
  • Do not assume a directory listing exists; link-driven recursion only sees documents and links the server exposes.

Troubleshooting wget-to-directory jobs

“Permission denied” at the destination

The destination is not writable by your user, or a parent directory is restricted. Choose a directory you own, create it ahead of time, or correct its permissions according to your operating system’s policy. Avoid running a download as an administrator unless you understand the ownership consequences.

The file appears in the wrong place

Check whether the path was relative. A relative -P downloads is anchored to the directory from which you launched Wget, not necessarily the directory containing your script. Use an absolute path while diagnosing, then switch to a relative path only when the working directory is controlled.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A recursive command retrieves too much

Lower -l, add -np, and narrow the starting URL. Remember that -l 0 is infinite depth. If the server links broadly across a site, a shallow level alone may still include more content than intended.

Expected files are missing

Wget can only follow links present in the retrieved HTML or CSS. Confirm that the starting page actually links to the files and that the server does not require a separate application workflow to reveal them. A non-browsable directory URL is not an index by itself.

All recursive content is in one odd file

Look for -O in the command. Remove it and use -P so each response can be written into the retrieval tree. The same correction applies when using -p for page requisites.

The command completed but the filename is unexpected

Wget determines names from the URL and server response. Read the transfer log, then use -O for a single download when a fixed filename is a requirement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Equivalent one-file downloads in other environments

When Wget is unavailable, these minimal examples save one response under a chosen name. They do not reproduce Wget’s recursive tree behavior.

cURL

curl -L https://example.com/file.zip -o downloads/file.zip

Python

import requests
r = requests.get("https://example.com/file.zip", timeout=90)
r.raise_for_status()
with open("downloads/file.zip", "wb") as f:
f.write(r.content)

Node.js

const fs = require('node:fs/promises');
const res = await fetch('https://example.com/file.zip');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
await fs.writeFile('downloads/file.zip', Buffer.from(await res.arrayBuffer()));

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create the destination directory before running these snippets, and add the authentication, retry and streaming behavior your application requires.

Or skip the browser setup

If your actual goal is a rendered webpage image or PDF rather than downloading a raw file, ScreenshotNeo provides a single HTTP request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and the response identifies the result with X-Page-Verdict and X-Billed headers.

cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90); open("shot.webp", "wb").write(r.content)

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' }); const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo API documentation for parameters, including full-page capture, CSS selectors, device presets, PDF output, custom JavaScript, waits, request blocking, cookies, headers, geolocation, caching, signed links, asynchronous jobs and bulk capture. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Frequently Asked Questions

Which Wget version do these option names refer to?

The documented behavior and option names are from the GNU Wget 1.25.0 Manual. If your distribution ships another version, run wget --version and consult its local help or manual for differences.

Can a server expose files without showing a directory index?

Yes. Wget’s recursive mode follows links in retrieved HTML and CSS; it does not invent a listing for files that the starting page does not link.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Is GNU Wget paid software?

The GNU documentation describes Wget as a free utility. Your operating system may package or install it differently, but the command-line utility itself is free.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.