Tai Lung: gasps The Wuxi finger hold!
Po: Oh, you know this hold.
Tai Lung: You’re bluffing. You’re bluffing! Shifu didn’t teach you that!
Po: Nope. I figured it out. Skidoosh. — [Kung Fu Panda]

If you have many files and you want to rename them, you can use the below steps to accomplish that.

Bulk renaming files using end pattern (%)

If you want to rename all files with extension *.jpg to *.png.

For example below is the list of files in current directory

$ ls -ltr
total 0
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test1.jpg
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test2.jpg
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test3.jpg
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test4.jpg
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test5.jpg
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test6.jpg
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test7.jpg
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test8.jpg
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test9.jpg
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test10.jpg

${var%pattern} : will trim pattern from var from the rear end. Using this technique, we can iterate through the list of files and rename files like below.

$ for FILE in $(find . -name "*.jpg"); do mv $FILE ${FILE%.jpg}.png; done
$ ls -ltr
total 0
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test1.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test2.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test3.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test4.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test5.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test6.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test7.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test8.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test9.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 test10.png

Bulk renaming files using start pattern (#)

If you want to rename all files starting with test to abc.

${var#pattern} : will trim pattern from var from front. Using this technique, we can iterate through the list of files and rename files like below.

$ for FILE in $(find . -name "*.png"); do mv $FILE abc${FILE#./test}; done
$ ls -ltr
total 0
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 abc1.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 abc2.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 abc3.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 abc4.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 abc5.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 abc6.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 abc7.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 abc8.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 abc9.png
-rw-r--r--  1 rchint1  Domain Users  0 Jul 18 20:02 abc10.png

Skidoosh

– RC