Skip to content
Latchkey

wget -P: Set the Download Directory

wget -P <dir> places downloaded files under the given directory, keeping their original names.

When you want a file to keep its server-side name but land in a specific folder, -P is the right tool, not -O.

What it does

wget -P <prefix> (--directory-prefix) sets the directory under which files are saved. The filename still comes from the URL (or Content-Disposition with --content-disposition). wget creates the prefix directory if it does not exist.

Common usage

Terminal
wget -P ./downloads https://example.com/app-1.2.0.tar.gz
# combine with recursive mirroring
wget -P ./mirror -r -np https://example.com/files/

Options

FlagWhat it does
-P <dir>Directory prefix for saved files
--directory-prefix=<dir>Long form of -P
-O <file>Choose the full output path/name instead
-ndDo not create host/path subdirectories

In CI

Use -P to drop artifacts into a known directory that a later step or cache picks up, while letting the file keep its versioned name. Unlike -O, which forces one name, -P preserves the source filename, which is useful when the version is part of it.

Common errors in CI

Permission denied means the prefix directory or its parent is not writable; point -P at a writable path such as the workspace or /tmp. If files land in nested host/path folders you did not expect during a recursive download, add -nd to flatten into the prefix directory.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →