How to batch rename files in shell

Say you have files abc0.ext, abc1.ext, ... abc257.ext that you want to rename to def0.ext, def1.ext, ... def257.ext.

You can either use the "rename" command if you have it (http://unixhelp.ed.ac.uk/CGI/man-cgi?rename) or you can use a for loop, mv and sed together, like this:

for f in abc*.ext; do mv $f $(echo $f | sed 's/^abc/def/g'); done


Comments

Popular Posts