Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get real filename from wget

I am writing a bash script and using wget to retrieve some PDF files form a website. For example:

wget www.barb.co.uk/news/item-subscriber/id/213/index.html

But wget saves the file as index.html. If I am in a browser and enter that URL, it correctly downloads the file with it's real name - "BARB Bulletin 25 - December 10.pdf".

How can I get wget to do the same? Or is there another way I can find the real name of the file (from within a bash script)?

like image 976
Peter Howe Avatar asked Nov 12 '12 11:11

Peter Howe


People also ask

How do I get files from wget?

Downloading a file In order to download a file using Wget, type wget followed by the URL of the file that you wish to download. Wget will download the file in the given URL and save it in the current directory.

How do I specify a filename in wget?

By default, downloaded file will be saved with the last name mentioned in the URL. To save file with a different name option O can be used. Syntax: wget -O <fileName><URL>

What is -- content disposition in wget?

Explanation: The Content-Disposition header can be used by a server to suggest a filename for a downloaded file. By default, wget uses the last part of the URL as the filename, but you can override this with --content-disposition , which uses the server's suggested name.

Can wget resume download?

To resume a wget download it's very straight forward. Open the terminal to the directory where you were downloading your file to and run wget with the -c flag to resume the download.


1 Answers

You can use the --content-disposition option to make wget have a more sophisticated look into the headers of the HTTP response, which helps in most cases.

Example:

wget --content-disposition www.barb.co.uk/news/item-subscriber/id/213/index.html
like image 114
hoeni Avatar answered Sep 24 '22 11:09

hoeni