Bash – How to rename part of the filename in multiple files

bashbatch-rename

I have numerous files in a directory with a variety of names that have one pattern in common—the file names end with _rgb.jpg. I'm looking for a simple command that will change that name ending to _cmyk.jpg on multiple files in that directory. I would prefer to do this in the command line.

Best Answer

Here is a quick script I made.

#!/bin/bash
for file in *_rgb.jpg
do
   echo mv ${file} ${file%_rgb.jpg}_cmyk.jpg
done

If you're happy with the results remove the echo

Related Question