Simple example of bash script that is changing files extension in desired directory:
#!/bin/bash
CURRENT_EXTENSION="${1-mp3}"
NEW_EXTENSION="${2-mp4}"
FILES_PATH="${3-$PWD}"
FILES_LIST=$(find ${FILES_PATH} -maxdepth 1 -name "*.${CURRENT_EXTENSION}")
for FILE in $FILES_LIST; do
NEW_FILE=$(echo "$FILE" | sed "s/${CURRENT_EXTENSION}/${NEW_EXTENSION}/")
echo "Renaming file: $FILE -> $NEW_FILE"
mv $FILE $NEW_FILE
done
Usage
You can use it by simple executing file:
./change_ext.sh
It will be executed with default settings: extensions to change: mp3, new extension will be mp4 and script will look for files in current directory.
It is also possible to overwrite settings:
./change_ext.sh csv txt /tmp
It will change all csv extensions to txt in /tmp directory.