Commands.page Logo

Ubuntu wget Command Ignore Server Suggested Filename

This article explains how to download files on Ubuntu using the command line while controlling the local filename. It focuses on the wget utility, which is standard in Linux environments, and details how to prevent the server from overriding your chosen file name via HTTP headers.

The primary command to download a file while ignoring the server’s suggested filename is wget. By default, wget uses the filename found in the URL rather than any name suggested by the server in the Content-Disposition header. To ensure the server never dictates the filename, you can explicitly specify the output name using the -O flag.

To download a file and set a custom name, use the following syntax:

wget -O desired-filename.txt https://example.com/file

In this command, desired-filename.txt is the name saved on your Ubuntu system, regardless of what the remote server suggests. If you run wget without the -O flag, it still ignores the Content-Disposition header by default, using the last part of the URL instead. However, using -O guarantees the name matches your input exactly.

Avoid using the --content-disposition flag with wget. Enabling this option tells wget to respect the server’s suggested filename, which is the opposite of the desired behavior for this task. Stick to the standard wget command or the -O option to maintain full control over your file naming convention.