#!/bin/bash time=$(date +%Y-%m-%d_%H%M%S) scanimage -b -x 214.98 -y 294.973 for img in out*.pnm; do newfile="${time}_$((i++)).jpg" convert "$img" "$newfile" && rm "$img" done