Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wget specify downloaded file name and no other file

Tags:

wget

I want to use wget so that my file takes on the name I want. For example, if I do wget -r http://www.x.com/y/z, the main file will be named z, even though it's actually index.html.

I checked the -O option of wget, but according to the manual:

‘-O file’
‘--output-document=file’
The documents will not be written to the appropriate files, but all will be concatenated together and written to file. ...

It seems like all the files will be concatenated and written to the file of the desired name. I would like only the main file (and not any file resulting from recursion) to be concatenated. How can I do that?

like image 428
Paul S. Avatar asked May 05 '13 15:05

Paul S.


People also ask

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?

Use wget --content-disposition <url> 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.

What is the difference between curl and wget?

The main difference between them is that curl will show the output in the console. On the other hand, wget will download it into a file.

Can wget download multiple files?

With wget , you can download multiple files, resume partial downloads, mirror websites, and combine the Wget options according to your needs.


2 Answers

Leave out the -r if you only want the main file:

wget -O customFileName http://www.x.com/y/z

wget does not support renaming just one file of a recursive download. Remember that filenames correspond to parts of the URL and renaming the file would break links between files. You can always either break it in two:

wget -O customFileName http://www.x.com/y/z
wget -r http://www.x.com/y/z

or just rename the file yourself:

wget -r http://www.x.com/y/z
mv z customFileName
like image 81
Old Pro Avatar answered Sep 20 '22 08:09

Old Pro


Try appending a / to the end of the URL:

$ wget -r http://www.x.com/y/z/

This results in an index.html file being saved instead of a z file

like image 23
Tim Heap Avatar answered Sep 18 '22 08:09

Tim Heap