In bash:
$ for f in * ; do if [ -f "$f" ] ; then t="${f%.*}" ; mv -i "$f" "$t".ext ; fi ; done
Explained:
for f in * # loop all items in the current dir
do
if [ -f "$f" ] # test that $f is a file
then
t="${f%.*}" # strip extension off ie. everything after last .
mv -i "$f" "$t".ext # rename file with the new extension
fi
done
Test:
$ touch foo bar baz.baz
$ mkdir dir ; ls -F
bar baz.baz dir/ foo
$ for f in * ; do if [ -f "$f" ] ; then t="${f%.*}" ; mv -i "$f" "$t".ext ; fi ; done
$ ls
bar.ext baz.ext dir/ foo.ext
Some overwriting might happen if, for example; there are files foo
and foo.foo
. Therefore I added the -i
switch to the mv
. Remove it once you understand what the above script does.