How to recursively and automatically convert all bmp images to png files in a given directory?

A simple for loop might be enough for a single directory:

for i in *.bmp
do 
convert $i "${i%.bmp}.png"
done

To make this truly recursive there are a few choices, one method is the following:

find . -name '*.bmp' -type f -exec bash -c 'convert "$0" "${0%.bmp}.png"' {} \;

If you wish to dabble a bit more you specify a quality level for the png level by using the syntax:

-quality value

This takes a value of 1 for the lowest quality and smallest file size to 100 for the greatest quality and largest file size. The default is approximately 92. Further details here...


I'd say the answer by andrew.46 is still the best, being it is an eloquent on-liner. However, here is another option. The only advantage is that there is a "current file number count" out of "total number of files" to convert, and it echoes the file being converted. You'll want to remove any spaces in file names though before running. This will remove spaces: find . -name "* *" | rename 's/ /-/g'

#!/bin/bash

cd $(pwd)    
bmp_files=$(find . -iname "*.bmp")

total=$(echo "$bmp_files" | wc -l)
num=0

echo "There are $total files to be converted."

for f in $bmp_files
do
    ((num++))
    echo "Converting $f, $num/$total"   
    convert "$f" "${f%.bmp}.png" 
    clear
done