You can use find to find all the files and then pass them to the while read :
$ find . -name "*.ext1" -print0 | while read -d $'\0' file do mv $file "${file%.*}.ext2" done
${file%.*} is a filter with a small right pattern. % indicates the pattern to delete on the right side (the corresponding smallest ball pattern),. .* is the pattern (last . , followed by the characters after . ).
-print0 will split file names with the NUL instead of \n . -d $'\0' will be read in file names separated by the NUL . Thus, file names with spaces, tabs, \n or other stupid characters will be processed correctly.
David W. Oct 03 '13 at 17:23 2013-10-03 17:23
source share