2

Bash :: Extension change script

A simple script to recursively change filename extensions (case insensitive)

#!/bin/bash
#chext.sh
 
ARGS=("$@")
 
if [[ -d ${ARGS[0]} && ${ARGS[1]} && ${ARGS[2]} ]]; then
        for x in $(find ${ARGS[0]} -name "*.${ARGS[1]}"); do
                y=$(echo $x | sed "s/\.${ARGS[1]}\$/\.${ARGS[2]}/i")
                mv $x $y
                echo "$x -> $y"
        done
else
        echo 'USAGE: chext.sh'
fi

2 Comments

  1. James
    Saturday 2, 2010

    Any reason you don’t just use perl’s rename?

  2. Zachary Schneider
    Saturday 2, 2010

    Not really a perl jockey. It was more of an exercise with shell scripting. Were I to use a scripting language I would probably have used os.rename from Python.

Leave a Reply

Spam protection by WP Captcha-Free