User Tools

Site Tools


lbaops:renamingfiles

Renaming a bunch of files at the same time

There is a command called rename which takes Perl-type regular expressions and acts on a list of files that you give it.

For example, say you have recorded an experiment with the name v276a, when the experiment was really v252f. At the end of the recording you will have a bunch of files that are named like:
v276a_Cd_161_005250.lba
v276a_Cd_161_005300.lba
v276a_Cd_161_005310.lba

and so on.

Now you want to keep the date information and station information, and you don't want to issue a thousand commands like:
mv v276a_Cd_161_005250.lba v252f_Cd_161_005250.lba

Use the rename command to do it for you, like this:
rename 's/v276a/v252f/' *

This command means “look for any instance of the string v276a and replace it with v252f, and do this for every file in the directory”. Voila, now the files will be named like:
v252f_Cd_161_005250.lba
v252f_Cd_161_005300.lba
v252f_Cd_161_005310.lba

lbaops/renamingfiles.txt · Last modified: 2015/12/18 16:39 (external edit)