14 Sep 2008, 00:00

Linux Mass Rename Recursively using a Bash Script

This example Bash script replaces “.JPG” with “.jpg” recursively in the current directory (It can handle filenames with spaces):

#!/bin/bash

find ./ -type f -name "*.JPG" | while read FILE
do
newname=echo $FILE | sed s/.JPG/.jpg/
echo $newname
mv "$FILE" "$newname"
done

Convert all characters to lowercase:

#!/bin/bash

find ./ -type f -name "*" | while read FILE
do
newname=echo $FILE | tr 'a-z' 'A-Z'
echo $newname
mv "$FILE" "$newname"
done