Renaming part of a filename

not_a_geek picture not_a_geek · Sep 8, 2009 · Viewed 104.9k times · Source

I have loads of files which look like this:

DET01-ABC-5_50-001.dat
...
DET01-ABC-5_50-0025.dat

and I want them to look like this:

DET01-XYZ-5_50-001.dat
...
DET01-XYZ-5_50-0025.dat

How can I do this?

Answer

Paul Dixon picture Paul Dixon · Sep 8, 2009

There are a couple of variants of a rename command, in your case, it may be as simple as

rename ABC XYZ *.dat

You may have a version which takes a Perl regex;

rename 's/ABC/XYZ/' *.dat