Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming part of a filename [duplicate]

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?

like image 825
not_a_geek Avatar asked Sep 08 '09 08:09

not_a_geek


People also ask

How do I change part of multiple file names?

Type the following command to rename the part of the file name and press Enter: ren OLD-FILE-NAME-PART*. * NEW-FILENAME-PART*. * In the command, replace "OLD-FILE-NAME-PART" and "NEW-FILENAME-PART" with the old and new parts of the filename.

How do I delete part of a file name in bulk?

Alternatively, head to the folder containing the files you want to delete, hit Shift + Right Click, and select Open a command window here. Then input "del [filename]" and press Enter.

How do you rename part of a file in Linux?

Rename Files in Linux using the rename Command. The mv command is a handy tool to rename single files, but if you want to rename multiple files, then you have to use a tool that is specifically made for this. Rename command is used to rename multiple files. This command requires basic knowledge of regular expressions.


2 Answers

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 
like image 91
Paul Dixon Avatar answered Oct 09 '22 13:10

Paul Dixon


for file in *.dat ; do mv $file ${file//ABC/XYZ} ; done 

No rename or sed needed. Just bash parameter expansion.

like image 35
RJ Alten Avatar answered Oct 09 '22 12:10

RJ Alten