Ubuntu: Download image from URL with wget and change the file name automatically


I want to download all the images from an URL using wget and set the name of output file based on the url.

For example, if I download this picture:

wget https://www.electrictoolbox.com/images/icons/linux-bsd.gif  

The filename will be linux-bsd.gif but I want it to be images_icons_linux-bsd.gif

I would like it to be automated.

How can I achieve this?


Finding all images of a website

As explain here, you can do so with the following:

# get all pages  curl 'http://domain.com/id/[1-151468]' -o '#1.html'    # get all images  grep -oh 'http://pics.domain.com/pics/original/.*jpg' *.html >urls.txt    # download all images  sort -u urls.txt | wget -i-  

Getting the Image

Here's a bash script, taking a URL as the first parameter:
#!/bin/bash  name=`echo $1 | sed 's/\//_/g' | sed 's/https:__[a-z\.]\+_//g'`  wget -O $name $1   

It may not work with some URLs, just so you know.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »