Linux: How to change the extension of a bunch of files?

Solution 1:

Take a look at the rename command: rename .xxx .yyy *.xxx

Solution 2:

 for i in *.xxx; do 
     mv "$i" "${i%.*}.yyy"
 done

The percent sign in "${i%.*}" means use the glob pattern that is after the percent sign, apply it to the value of the variable i, and remove the shortest possible match from the tail end of that value. This called Parameter / Variable expansion, and has many uses. You can also make it so the glob is longest possible match or make the glob match from the start as well. This Linux Journal article is all about parameter expansion.

It is put in double quotes so that if there are spaces in the filename and the IFS variable is set to include spaces (the norm), the filename will still be passed to mv as one argument.

Solution 3:

Install mmv and then do this:

mmv -r "*.xxx" "#1.yyy"

Solution 4:

Already a bunch of answers, but I'll add my own.

for i in *.xxx; do
    mv "$i" "`basename $i .xxx`.yyy"
done