Let's say you have a set of files in a directory named like exp1eve1.txt exp1eve2.txt exp1eve3.txt exp1eve4.txt and you want to change the exp1 part to exp2 so they become exp2eve1.txt exp2eve2.txt ... There are so many ways to do the job. Using Substring Expansion one could do #!/bin/bash for i in exp1eve*.txt; do mv "$i" "${i:0:3}2${i:4:$((${#i}-3))}" done How does the substring expansion