Dynamic download endpoints frequently expose a stable URL that returns different files based on query parameters or request context. Many of these endpoints supply the intended filename via the HTTP Content-Disposition header instead of embedding it directly in the URL. Aligning local filenames with this header keeps downloaded assets consistent with expectations in documentation, backup routines, and downstream tooling.

By default, wget chooses the output filename from the last path component of the URL or from an explicitly provided --output-document argument. When the --content-disposition command-line option or the corresponding content_disposition setting in the configuration file is enabled, wget inspects the server’s Content-Disposition header and, when the value passes its safety checks, uses that header’s filename= parameter as the local filename instead of the URL segment.

Because Content-Disposition values are entirely controlled by the remote server, blindly trusting them can result in confusing names, overwrites, or unsafe paths if directory separators appear in the header. Enabling header-driven naming globally affects every subsequent download for that account, so configuration should be validated interactively against trusted HTTPS endpoints before incorporating wget into unattended cron jobs or deployment pipelines.

Steps to honor Content-Disposition filenames in wget:

  1. Open a terminal in the directory intended to receive downloads.
    $ pwd
    /home/user/downloads
  2. Confirm that the installed wget build supports the --content-disposition option.
    $ wget --help | grep -- '--content-disposition'
           --content-disposition    honor the Content-Disposition header when choosing local file names

    If no line mentioning --content-disposition appears, upgrade wget or install a recent version that includes this feature.

  3. Perform a one-off test download using --content-disposition to observe the header-provided filename in action.
    $ wget --content-disposition 'https://example.com/download?id=42'
    --2025-12-07--  https://example.com/download?id=42
    Resolving example.com (example.com)... 93.184.216.34
    Connecting to example.com (example.com)|93.184.216.34|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1048576 (1.0M) [application/pdf]
    Saving to: ‘report-2024.pdf’
    
    report-2024.pdf              100%   1.0M  2.5MB/s    in 0.4s
    
    2025-12-07 12:34:56 (2.5 MB/s) - ‘report-2024.pdf’ saved [1048576/1048576]

    Header-controlled filenames can misrepresent file contents or attempt to overwrite existing data, so only run such downloads against trusted endpoints and review resulting filenames before automated processing.

  4. Enable honoring Content-Disposition filenames by default for the current account in the personal wget configuration file.
    $ printf '%s\n' 'content_disposition = on' >> ~/.wgetrc

    The personal configuration file ~/.wgetrc applies only to the invoking user, while system-wide defaults typically live in /etc/wgetrc.

  5. Verify that subsequent downloads automatically use the header-provided filename without explicitly passing --content-disposition.
    $ wget 'https://example.com/download?id=42'
    --2025-12-07--  https://example.com/download?id=42
    Resolving example.com (example.com)... 93.184.216.34
    Connecting to example.com (example.com)|93.184.216.34|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1048576 (1.0M) [application/pdf]
    Saving to: ‘report-2024.pdf’
    
    report-2024.pdf              100%   1.0M  2.5MB/s    in 0.4s
    
    2025-12-07 12:34:57 (2.5 MB/s) - ‘report-2024.pdf’ saved [1048576/1048576]

    Successful configuration is indicated by the Saving to: 'report-2024.pdf' line appearing without specifying --content-disposition on the command line.

Discuss the article:

Comment anonymously. Login not required.