Shell Scripting – How to Rename Multiple Files by Replacing Word in File Name

filesrenamesedshell

Replace ACDC to AC-DC

For example we have these files

ACDC – Rock N' Roll Ain't Noise Pollution.xxx

ACDC – Rocker.xxx

ACDC – Shoot To Thrill.xxx

I want them to become:

AC-DC – Rock N' Roll Ain't Noise Pollution.xxx

AC-DC – Rocker.xxx

AC-DC – Shoot To Thrill.xxx

I know that sed or awk is used for this operation. I can't google anything so I'm asking for your help =) Could you please provide full working shell command for this task?

Feedback: Solution for OSX users

Best Answer

rename 's/ACDC/AC-DC/' *.xxx

from man rename

DESCRIPTION
       "rename" renames the filenames supplied according to the rule specified as the 
first argument.  The perlexpr argument is a Perl expression which is expected to modify the 
$_ string in Perl for at least some of the filenames specified.  If a given filename is not 
modified by the expression, it will not be renamed.  If no filenames are given on
           the command line, filenames will be read via standard input.

For example, to rename all files matching "*.bak" to strip the extension, you might say

rename 's/\.bak$//' *.bak

To translate uppercase names to lower, you'd use

rename 'y/A-Z/a-z/' *
Related Topic