Решение, основанное на собственных функциях bash (ну, кроме find, затем ;-))
#!/bin/bash
files=`find . -type f -name *.jpg`
for f in $files
do
echo
echo $f
# convert f to an array
IFS='/'
a=($f)
unset IFS
# now, the folder containing a digit
# are @ index [2]
# small, medium, large are @ [3]
# and name of file @ [4]
echo ${a[2]} ${a[3]} ${a[4]}
echo ${a[3]}_${a[2]}.jpg
done