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.
find . -name "thumb_*.jpg" -exec echo "mv '{}' '{}'" \; | sed 's/thumb_/tn_/2' | /bin/sh
You're genius! I wish I knew this earlier!
vBulletin® v3.8.1, Copyright ©2000-2026, Jelsoft Enterprises Ltd.