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.jpg
filename=$(basename "$url")
wget "$url"

Tags:

Linux

Bash

Wget