Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have over 200 html files, each containing a png format picture, stored on my harddisk.

How can I extract those pictures into a separate folder easily?

share|improve this question
Where are the pictures stored? They can't be embedded in the HTML file, the pictures must be referenced, either to a local png file or in the web. – mrcktz Nov 3 '12 at 0:37
I am sure you mean 'complete webpages', as when you save these in your browser, you gain both a .html file and a _files folder; it is the later that actually contains any images. – user76204 Nov 3 '12 at 16:51
Do you need to keep any of the hierarchy info (that is, names of folders that pictures currently exist in)? Do you care if a solution is command-line or GUI-based? – belacqua Nov 3 '12 at 20:03

When you save a complete webpage in your browser, you will have the html file, for example, Mik.html and its accompanying objects (js and pictures etc) in a file called, for example, Mik_files. Obviously, what you want is in those associated folders and not actually within the html file.

What I do is use the following script, which, in this case, finds all the .png images in the accompanying _files folders saved with the html pages. The images are moved to the directory you choose, although it must exist. The script can be modified as you wish-I have used two positional parameters $1 and $2 so you can choose which directory to target ($1) and where to copy the files that are found ($2). Run chmod u+x it to make it executable. You could add another positional parameter if you don't want it to just find .png files each time.

As an example, if it is not in your ~/bin, you could call it with:

./ $HOME/Downloads $HOME/Documents

The contents of the script:


find "$1" -type f -iname '*.png' -print0 | \
while IFS= read -r -d '' f
    mv -- "$f" "$2"  

exit 0 
share|improve this answer
that was very helpful, thanks Mik – user90939 Nov 3 '12 at 23:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.