Mass change a portion of a file name?

I have a whole bunch of files named as following (example):

ADVANTE  18''8.0 PCD5'114.3 ET45 CB73.1.jpg
ADVANTE  18x8.0 PCD6139.7 ET20 CB110.2.jpg
ADVANTE 'A MI576B 20''8.5 PCD6'139.7 ET25 CB110.2 GBXZLDCP.jpg
ADVANTE 'A SH10 15''6.5 PCD8'100-114.3 ET40 CB73.1 3FPBU.jpg

How do I go to each file and change a portion of their filename to:

ADVANTI  18''8.0 PCD5'114.3 ET45 CB73.1.jpg
ADVANTI  18x8.0 PCD6139.7 ET20 CB110.2.jpg
ADVANTI 'A MI576B 20''8.5 PCD6'139.7 ET25 CB110.2 GBXZLDCP.jpg
ADVANTI 'A SH10 15''6.5 PCD8'100-114.3 ET40 CB73.1 3FPBU.jpg

using some sort of command or app? It would take too long to rename each and every one of them manually.


Solution 1:

If you use the ZSH shell, this can be done easily in Terminal with zmv (included with OS X by default). Why use fancy scripts if the work is already done?

Type zsh in a terminal window if for some crazy reason you do not have it set as your default shell.

autoload zmv
zmv 'ADVANTE(*)' 'ADVANTI$1'

Solution 2:

As of OS X 10.10 (Yosemite), you can use the Finder to search-and-replace strings in filenames. Select the files you want to rename, then invoke the Rename… option. You should see a dialog sheet with Find: and Replace with: fields.

Solution 3:

In case you need to do this often (and with different file patterns), this perl script might proof very useful. Store the following script as a text file called rename in a convenient place:

#!/usr/bin/perl -w
# rename - Larry's filename fixer
$op = shift or die "Usage: rename expr [files]\n";
chomp(@ARGV = <STDIN>) unless @ARGV;
for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}

You can then use all the standard perl expressions to rename files, in your case

rename 's/^ADVANTE/ADVANTI/' ADVANTE*