Updated: 9 October 2026 · Applies to: GNU Wget 1.25.0 on Debian 13 (all examples tested), Wget 1.21.1 on Rocky Linux 9 (-P tested), Wget 1.25.0 on Ubuntu 26.04 and 1.24.5 on AlmaLinux 10 (package versions checked), GNU Wget2 2.2.1 on Fedora 44 (tested)

wget saves every download in the current directory, the folder pwd shows, under the file name from the URL. To set the output directory, add -P (long form --directory-prefix). wget creates the folder if it does not exist:

wget -P /srv/downloads https://ftp.gnu.org/gnu/hello/hello-2.12.tar.gz.sig

To choose the folder and the file name at once, use -O with a full path instead: wget -O /srv/downloads/hello.sig URL. Unlike -P, -O does not create missing folders.

Where does wget save files?

Look for the Saving to: line in wget's output. Run in /root, a plain download looked like this (shortened):

$ wget https://ftp.gnu.org/gnu/hello/hello-2.12.tar.gz.sig
HTTP request sent, awaiting response... 200 OK
Length: 488 [application/pgp-signature]
Saving to: 'hello-2.12.tar.gz.sig'
... 'hello-2.12.tar.gz.sig' saved [488/488]

The path in quotes is relative to the folder you ran wget in, so the file is /root/hello-2.12.tar.gz.sig. Points worth knowing:

  • If a file with that name already exists, wget does not overwrite it. It saves the new copy as hello-2.12.tar.gz.sig.1, then .2 and so on.
  • -nc skips the download instead: File 'hello-2.12.tar.gz.sig' already there; not retrieving.
  • -N downloads again only when the remote file is newer, and -c continues a partial download.
  • In scripts and cron jobs, always give an absolute folder with -P, so the file does not land in whatever directory the job happens to start in.

Download a file to a specific directory

  1. Download with -P; the folder is created for you:
    $ wget -nv -P /srv/downloads https://ftp.gnu.org/gnu/hello/hello-2.12.tar.gz.sig
    (one log line, omitted)
    $ ls -l /srv/downloads
    total 4
    -rw-r--r-- 1 root root 488 Jan 31  2022 hello-2.12.tar.gz.sig
  2. Or set the full path with -O. If the folder is missing, wget fails with exit code 1:
    $ wget -nv -O /srv/nothere/hello.sig https://ftp.gnu.org/gnu/hello/hello-2.12.tar.gz.sig
    /srv/nothere/hello.sig: No such file or directory
    Create it first with mkdir -p /srv/nothere. More on choosing names: how to rename a file while downloading with wget.
  3. Download many files into one folder from a list (one URL per line): wget -i urls.txt -P /srv/downloads

Recursive download into a folder

-r follows the links on a page or directory listing. Combine it with these options to keep the result tidy:

  • -np (no parent): never go up to the parent directory.
  • -nd (no directories): put every file straight into the -P folder.
  • -nH --cut-dirs=1: keep the folder structure but drop the host name and the first remote folder.
  • -l 1: how many levels deep to go. The default is 5, according to the GNU Wget manual.
  • -A and -R: accept or reject files by suffix or name pattern, for example -A "*.iso" or -R "*.html". Start a pattern with * so it also works with Wget2 (see Fedora below).

This fetched only the hello 2.12 signature files from a directory listing:

$ wget -r -np -nd -A "*hello-2.12*.sig" -P /srv/hello https://ftp.gnu.org/gnu/hello/
Removing /srv/hello/index.html.tmp since it should be rejected.
Saving to: '/srv/hello/hello-2.12.1.tar.gz.sig'
Saving to: '/srv/hello/hello-2.12.2.tar.gz.sig'
Saving to: '/srv/hello/hello-2.12.3.tar.gz.sig'
Saving to: '/srv/hello/hello-2.12.tar.gz.sig'
Downloaded: 14 files, 98K in 0.002s (43.7 MB/s)

(Output filtered.) wget has to download the index pages to find the links, then deletes them because they do not match -A. In recursive mode, wget also reads and respects the site's robots.txt. With -nH --cut-dirs=1 instead of -nd, the same kind of download landed in /srv/mirror/hello/.

wget and wildcards

Over HTTP and HTTPS, wget does not expand * in a URL. It asks the server for a file literally named with a star:

$ wget -nv "https://ftp.gnu.org/gnu/hello/hello-2.1*.tar.gz.sig"
https://ftp.gnu.org/gnu/hello/hello-2.1*.tar.gz.sig:
ERROR 404: Not Found.

Use a recursive download with -A as shown above. Wildcards in the URL work only for FTP, which wget lists and matches itself (quote the URL so your shell leaves the * alone):

$ wget -nv "ftp://ftp.gnu.org/gnu/hello/hello-2.1*.tar.gz.sig" -P /srv/ftp
(log lines omitted)
$ ls -1 /srv/ftp
hello-2.10.tar.gz.sig
hello-2.11.tar.gz.sig
hello-2.12.1.tar.gz.sig
hello-2.12.2.tar.gz.sig
hello-2.12.3.tar.gz.sig
hello-2.12.tar.gz.sig

Fedora: wget is now Wget2

On Fedora 44, dnf install wget installs GNU Wget2 2.2.1 (package wget2-wget), and wget is a link to wget2. -P, -O, -nc, -r and the .1 suffix work as above, with three differences we saw:

  • -O /missing/folder/file creates the missing folders instead of failing.
  • There is no FTP support: the FTP wildcard download printed Failed to parse URI and Nothing to do - goodbye.
  • An -A pattern without a leading star ("hello-2.12*.sig") saved nothing; "*hello-2.12*.sig" worked.

Debian, Ubuntu, AlmaLinux and Rocky Linux still ship the classic GNU Wget 1.x as wget.

If wget is missing

sudo apt install wget      # Debian, Ubuntu
sudo dnf install wget      # AlmaLinux, Rocky Linux, RHEL, Fedora

curl can also save into a folder: curl -L --output-dir /srv/downloads -O URL (add --create-dirs if the folder does not exist yet). See curl command tips, how to limit the download speed with wget and how to download and extract a tar file in one command.

Official documentation: GNU Wget manual.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket