Rename a Specific Word in Filenames

1. As an example, you are going to rename/replace the DEV word to PRD word under the directory /usr/sap/DEV which contains the following filenames.

# cd /usr/sap/DEV
# ls -lrt
DEVdata1.txt
DEVdata2.txt
DEVdata3.txt
DEVdata4.txt
DEVdata5.txt
DEVdata6.txt
DEVdata7.txt
DEVdata8.txt
DEVdata9.txt
DEVdata10.txt
DEVdata11.txt
DEVdata12.txt

2. Execute the following command. This will change all the filenames that contained the DEV word to PRD word.

# ksh
# for i in PRD*; do mv "$i" DEV"${i#PRD}"; done

You May Also Like

Leave a Reply?