Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Replace ACDC to AC-DC

For example we have these files

ACDC - Rock N' Roll Ain't Noise


ACDC - Shoot To

I want them to become:

AC-DC - Rock N' Roll Ain't Noise


AC-DC - Shoot To

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

share|improve this question
I sense there is a larger question here - are you trying to fix up mp3 filenames in general? There are a number of scripts people have written over the years to do this. I think one I've used was called mp3fixer. – Phil Hollenback Jan 30 '11 at 8:34
no it's not about mp3's I just have to manage some huge files with similar names, and something everything must be replaced or fixed... common situation so I need this nifty solution for renaming all of them – holms Jan 30 '11 at 14:36
up vote 25 down vote accepted
rename 's/ACDC/AC-DC/' *.xxx

from man rename

       "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/' *
share|improve this answer
Note that many linux machines come with rename from util-linux, which implements simple substitution, not regexes. So if rename fails silently without doing anything, you're probably using the wrong rename. – Phil Hollenback Jan 30 '11 at 8:31
I was searching this for ages! thnx! – holms Jan 30 '11 at 14:39

This answer contains the good parts from all other answers, while leaving out such heresy as ls | while read.

Current directory:

for file in ACDC*.xxx; do
    mv "$file" "${file//ACDC/AC-DC}"

Including subdirectories:

find . -type f -name "ACDC*" -print0 | while read -r -d '' file; do
    mv "$file" "${file//ACDC/AC-DC}"

Newline characters are really unlikely to be in filenames, so this can be simpler while still working with names containing spaces:

find . -type f -name "ACDC*" | while read -r file; do
    mv "$file" "${file//ACDC/AC-DC}"
share|improve this answer

Using the bash shell

find . -type f -name "ACDC*" -print0 | while read -d $'\0' f
   new=`echo "$f" | sed -e "s/ACDC/AC-DC/"`
   mv "$f" "$new"

Note: using find will process the current directory, and the directories under.

share|improve this answer

To use the util-linux version of rename that Phil referred to (on Ubuntu, it's called rename.ul):



rename.ul ACDC AC-DC ACDC*
share|improve this answer
your variant is the best =) so many stupid articles in google about find and send and awk... to this simple operation for which renameutils egxist already! – holms Jan 30 '11 at 15:23

Depends on your shell. In zsh, I'd do this:

for file in ACDC*.xxx; do
    mv "$file" "$(echo $file | sed -e 's/ACDC/AC-DC/')"

Probably not the best solution, but works.

share|improve this answer

Using bash:

ls *.xxx | while read fn; do
    mv "${fn}" "${fn/ACDC/AC-DC}";

If you have the rename program installed:

rename 's/ACDC/AC-DC/' *.xxx
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.