Wget: Keep Original Filename

If you try to download a file over HTTP/HTTPS provided by a dynamic link or through a chain of 301, 302 redirects, wget would normally save the file using a part of the URL that you’re using.

At the same time, if you use this URL to download the file in a browser, it will be downloaded and saved with its original name.

In this note i will show how to force wget to preserve the original filename and save it with its actual name.

Cool Tip: How to backup a web-site over FTP using wget! Read more →

Keep Original Filename with Wget

By default, wget doesn’t automatically detect the original filename and save a file using a part of the provided URL, for example:

$ wget -nv --show-progress https://telegram.org/dl/desktop/linux
- sample output -
linux                           100%[====================>]  39,23M  1,87MB/s  in 28s
URL:https://updates.tdesktop.com/tlinux/tsetup.3.3.0.tar.xz -> "linux"

To download a file with wget and keep the original filename proposed by the server, use the --content-disposition option:

$ wget --nv --show-progress --content-disposition https://telegram.org/dl/desktop/linux
- sample output -
tsetup.3.3.0.tar.xz             100%[====================>]  39,23M  1,79MB/s  in 18s
URL:https://updates.tdesktop.com/tlinux/tsetup.3.3.0.tar.xz -> "tsetup.3.3.0.tar.xz"
Option Description
-nv, --no-verbose Turn off verbose but print the error messages and basic information.
--show-progress Force wget to display the progress bar in any verbosity.
--content-disposition Enable the support of a “Content-Disposition” header used to describe what the name of a downloaded file should be.
Was it useful? Share this post with the world!

Leave a Reply