Monday, June 7, 2010

rename file extension recursively

SkyHi @ Monday, June 07, 2010

Rename all *.info files in one folder

rename .info .txt *.info

That should read as..

rename

Do the same operation recursively in a directory tree

##below works in Centos, but no Ubuntu

find . -name "*.info" -exec rename .info .txt {} \;

REFERENCES
http://txt.binnyva.com/2007/03/change-the-extension-of-multiple-files-in-linux/



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):

###proved###
#!/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


REFERENCES
http://alexpb.com/notes/articles/2008/09/14/linux-mass-rename-recursivly-using-a-bash-script/