Updated: 4 November 2026 · Applies to: GNU Wget 1.25.0 (Debian 13, tested), Wget2 2.2.1 (Fedora 44, tested) and curl 8.14.1; Ubuntu 24.04 (Wget 1.21.4), AlmaLinux 9 (1.21.1) and AlmaLinux 10 (1.24.5) ship GNU Wget with the same options

To rename a file while downloading it with wget, use -O (capital letter O, long form --output-document) followed by the new name:

wget -O ca-bundle.pem https://curl.se/ca/cacert.pem

wget downloads cacert.pem but saves it as ca-bundle.pem:

HTTP request sent, awaiting response... 200 OK
Length: 188900 (184K) [application/x-pem-file]
Saving to: 'ca-bundle.pem'
...
'ca-bundle.pem' saved [188900/188900]

Put the URL in quotes if it contains ? or &, so the shell does not interpret those characters.

Rename and save in another folder

Give -O a full path:

wget -O /root/downloads/ca-bundle.pem https://curl.se/ca/cacert.pem
  • The folder must already exist. Otherwise wget stops with nodir/ca.pem: No such file or directory (create it first with mkdir -p).
  • -P (directory prefix) has no effect together with -O: wget -P /root/downloads -O ca-bundle.pem URL saved ca-bundle.pem in the current folder in our test, not in /root/downloads. Use -P alone when you want to keep the original name in another folder (see download files to a specific directory with wget).

Resume a renamed download

-c (continue) works with -O, as long as you use the same name again. We cut a 2.7 MB file at 1 MB and resumed it:

$ wget -c -O curl.tar.xz https://curl.se/download/curl-8.14.1.tar.xz
HTTP request sent, awaiting response... 206 Partial Content
Length: 2817248 (2.7M), 1817248 (1.7M) remaining [application/x-xz]
Saving to: 'curl.tar.xz'
        [ skipping 950K ]
...
'curl.tar.xz' saved [2817248/2817248]

The SHA256 checksum matched the complete download. Resuming needs a server that supports HTTP range requests.

What -O really does

The wget manual says -O is not meant as "use this name instead of the one in the URL": it works like shell redirection, so wget -O file URL behaves like wget -O - URL > file. In practice:

  • An existing file is overwritten without a question (a file with the same name was replaced in our test).
  • A failed download leaves an empty file. A URL that returned an error (exit code 8) still left a 0-byte missing.pem. Check the exit code (echo $?, 0 means success) in scripts.
  • Several URLs with one -O are joined into one file. wget -O both.txt URL1 URL2 wrote both downloads into both.txt. Use one wget command per file instead.
  • With -nc (no clobber), wget refuses if the file exists: File 'ca-bundle.pem' already there; not retrieving.
  • -O - sends the download to standard output, for example wget -qO - URL | tar xzf - (see download and extract tar files with one command).
  • According to the wget manual, -N (timestamp checking) is not supported with -O, and with -r or -p all content goes into that single file.

Let the server choose the name

Some download links do not end in a useful file name. Without -O, wget names the file after the last part of the URL you typed, query string included: wget "https://www.gnu.org/licenses/gpl-3.0.txt?ref=kb" saved gpl-3.0.txt?ref=kb. Two options change this:

  • --content-disposition uses the file name the server sends in the Content-Disposition header.
  • --trust-server-names names the file after the last part of the URL wget was redirected to.

For the GitHub link https://github.com/jqlang/jq/archive/refs/tags/jq-1.7.1.tar.gz (which redirects and sends content-disposition: attachment; filename=jq-jq-1.7.1.tar.gz) we got three different names:

wget URL                          -> jq-1.7.1.tar.gz
wget --content-disposition URL    -> jq-jq-1.7.1.tar.gz
wget --trust-server-names URL     -> jq-1.7.1

When you need a predictable name, -O is still the safest choice.

File already exists: why wget adds .1

Without -O, downloading the same file twice does not overwrite it. wget saves the second copy as cacert.pem.1, then .2 and so on. Use -O name to overwrite, -nc to skip existing files, or -c to resume a partial file.

Rename several downloads at once

Put each URL and its new name on one line in list.txt:

https://curl.se/ca/cacert.pem ca-bundle.pem
https://curl.se/ca/cacert.pem.sha256 ca-bundle.sha256

Then loop over it:

while read -r url name; do wget -q -O "$name" "$url"; done < list.txt

Both files were saved under the new names. (wget -i list.txt downloads a list too, but keeps the original names.)

The same with curl and Wget2

  • curl: curl -L -o newname URL saves under your name (-L follows redirects). curl -LO URL keeps the URL name and curl -LOJ URL uses the Content-Disposition name (it gave jq-jq-1.7.1.tar.gz for the GitHub link above). More in tips for the curl command.
  • Fedora: the wget command on Fedora 44 is Wget2 (package wget2-wget, GNU Wget2 2.2.1). -O, -c and --content-disposition gave the same results; its messages look different (Saving 'ca-bundle.pem'), and resuming a complete file prints The file is already fully retrieved; nothing to do.

You can also rename after the download with mv cacert.pem ca-bundle.pem. To keep big downloads from using all your bandwidth, see limit download speed with wget and curl.

Official documentation: wget(1) manual and curl 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