> esc
move open g h home ? help
$ cat /post/batch-rename-extensions.md

Batch rename extensions

Another snippet, this time to batch rename the extension of a set of files to another, in my case I needed to rename *.html files as .mustache so, as before, (when I set up a scripts folder in my user folder and added it to my path in my .bash_profile), and added this text file:

#!/bin/bashfor file in *.$1do  mv "$file" "${file%.$1}.$2"done

The first parameter $1 is the extension to find, the second $2 is the new extension. The for loop matches every file against *.$1 and runs mv on each; ${file%.$1} trims the old extension off before appending the new one.

I’ve called this script batchrenameext, placed it in the scripts folder, and marked it executable:

chmod +x batchrenameextbatchrenameext html mustache
$ env | grep ^CAT
CAT_01=scripting
CAT_02=sysadmin
$ env | grep ^TAG
TAG_01=bash