wget: downloaded file name wget: downloaded file name bash bash

wget: downloaded file name


wget --server-response -q -O - "https://very.long/url/here" 2>&1 |   grep "Content-Disposition:" | tail -1 |   awk 'match($0, /filename=(.+)/, f){ print f[1] }' )

This is the correct version as there are may be several 301/302 redirects and finally a Content-Disposition: header to set the file name

Guessing file name based on URL is not always correct.


Use the basename command to extract the filename from the URL. For example:

url=http://pics.sitename.com/images/191211/mxKL17DdgUhcr.jpgfilename=$(basename "$url")wget "$url"


You can just specify the filename before downloading, with the -O option to wget:

wget -O myfile.html http://www.example.com/