The rambling of an unimportant person

Download Images From a Text File

How to download images from a text file, and maybe retain the folder structure

Let's say you have a list of images that another tool has created. Let's say you need to download each of those images and then do something with them. Instead of manually pasting each URL into a browser and saving the image, this trick will do them all in one go.


Create a text file like, such as images.txt. Enter all the URLs into it like so:

https://mysite.com/image1.jpg
http://anothersite.com/lorem/ipsum/image1_1234.jpg
http://anothersite.com/profile.png?1234

Assuming you have wget installed, cd into the folder with the text file in, and run this:

wget -i images.txt

It'll download the image in the same folder, and you'll end up with a folder structure like this:

image1.jpg
image1_1234.jpg
profile.png?1234

And that's it! You now have all the images listed in the text file, saved locally.


Update: Jan 17th 2022

If you add -x after the file name, it will replicate the remote file structure. Taking our earlier example of:

https://mysite.com/image1.jpg
http://anothersite.com/lorem/ipsum/image1_1234.jpg
http://anothersite.com/profile.png?1234

With the updated command:

wget -i images.txt -x

Will yield the following:

mysite.com/image1.jpg
anothersite.com/lorem/ipsum/image1_1234.jpg
anothersite.com/profile.png?1234