PDA

View Full Version : Shell batch rename command/script


CelticTiger
2006-01-30, 06:17 AM
I'm hoping someone can help me figure out how to batch rename files recursively thru a directory on our server......ie I'd like to rename all files starting with "thumb_" to "tn_" leaving the remainder of the file name intact so that thumb_pic01.jpg would be renamed tn_pic01.jpg

Any help is greatly appreciated :)

swedguy
2006-01-30, 06:36 AM
find . -name "thumb_*.jpg" -exec echo "mv '{}' '{}'" \; | sed 's/thumb_/tn_/2' | /bin/sh

CelticTiger
2006-01-30, 06:55 AM
Nice one swedeguy Thanks alot! |thumb

Servhot
2006-01-30, 07:44 AM
Also MMV is a very nice tool for the shell which can not rename only, you also can move files, folders etc.

rtv
2006-01-31, 06:18 PM
find . -name "thumb_*.jpg" -exec echo "mv '{}' '{}'" \; | sed 's/thumb_/tn_/2' | /bin/sh


You're genius! I wish I knew this earlier!