Wget download files from a file list, how to specify names for each of the downloaded file

downloadfilenamesrenamewget

When downloading a single file, we can use wget's -O option to specify the file name. When I'm downloading Urls in a file using wget -i filelist.txt (filelist.txt contains list Of Urls I want to Download), how can I construct filelist.txt so that each file is renamed as it is downloaded?

For Ex, if the filelist.txt contains the following content:

--output-document=1.jpg http://images2.example.com/image1.jpg
--output-document=2.jpg http://images2.example.com/image2.jpg

Is it possible to download image1.jpg and save as 1.jpg, image2.jpg as 2.jpg?


Edit

I know I can use simple script or text manipulation techniques to create multiple wget commands and each of which downloads a single Url and write to an output file. I haven't tested but this seems slower to me and I want to know if there is any way to download all the files using a single wget process.

Best Answer

You can't do it purely in one invokation of Wget. This stems from the definition of Wget's -O option, which doesn't simply mean name of saved file, but rather is a shell redirection of stdout.

If all the names of the files are different on the server, then you can still do this fairly quickly by downloading all the files in a single invokation of Wget and then using a shell script to rename them.

You're right in that multiple invokations of wget will be slow. The process startup and teardown is one aspect, but needing to make a new HTTP connection to the server for each of the files can add up very quickly

Related Question