Ubuntu Bulk File Rename

Kevin FOO
1 min readDec 1, 2021

--

Renaming a file in Ubuntu I will use “mv”. When it comes to renaming multiple files and say append prefix to all the files, “mv” isn’t the right program for the job. I could write a bash script to loop each and every file, rename the files one by one through the loop. Or I could install a program called “rename”.

sudo apt install rename

Lets say I have these files in my folder

IMG_0001.JPG
IMG_0002.JPG
IMG_0003.JPG

To append the letter “A” as prefix.

rename 's/^/A/' *JPG
# AIMG_0001.JPG
# AIMG_0002.JPG
# AIMG_0003.JPG

To remove the prefix “A” after adding them

rename 's/^A//' *JPG
# IMG_0001.JPG
# IMG_0002.JPG
# IMG_0003.JPG

To append postfix “bak” to end of filename

rename 's/$/bak/' *JPG
# IMG_0001.JPG.bak
# IMG_0002.JPG.bak
# IMG_0003.JPG.bak

To replace all underscore “_” with dash “-”

rename 's/_/-/g' *JPG
# IMG-0001.JPG
# IMG-0002.JPG
# IMG-0003.JPG

< Back to all the stories I had written

--

--

Kevin FOO
Kevin FOO

Written by Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.