Skip to content
Advertisement

Using wget to download images and saving with specified filename

I’m using wget mac terminal to download images from a file where each image url is it’s own line, and that works perfectly with this command:

JavaScript

However I want to specify the output filename it’s saved as instead of using the basename. The file name is specified in the next column, separated by either space or comma and I can’t quite figure out how to tell wget to use the 2nd column as the name it should as the -O name.

I’m sure it’s a simple change to my above command but after reading dozens of different posts on here and other sites I can’t figure it out. Any help would be appreciated.

Advertisement

Answer

If you use whitespace as the seperator it’s very easy:

JavaScript

Explanation: instead of reading just one variable per line (${url}) as in your example, you read two (${url} and ${name}). The second one is your local filename. I assumed your images.txt file looks something like this:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement