wget specify downloaded file name and no other file

Paul S. picture Paul S. · May 5, 2013 · Viewed 16.1k times · Source

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?

Answer

Old Pro picture Old Pro · May 12, 2013

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