This is my homebrew bash script for batch renaming files extensions (my music library needs organizing):
#!/bin/bash
# rext.sh
# Syntax: rext.sh EXT1 EXT2
# Batch rename any file in current directory with extension of EXT1 to EXT2
EXT1=$1
EXT2=$2
for f in *.$EXT1
do
fname=${f%.*}
newfname="$fname.$EXT2"
mv -v -i "$f" "$newfname"
done
It works beautifully with my music files, but is this code sufficient or can I still improve on it? Also I've seen examples using rename
instead of mv
, so is there any advantage in using rename
?