Rename files by replacing a pattern in the filenames using a bash script


If you want to rename a big amount of files and you don’t want to to it one by one, you can use the following bash script.


for f in *.txt;
nf=`echo $f | sed s/OLD/NEW/`
mv $f $nf

This script will list all *.txt files and replace OLD by NEW in the filename.

You just have to modify the “*.txt” and the /OLD/NEW/ part to your needs and it will change all filenames by the given pattern.