Find the answer to your Linux question:
Results 1 to 3 of 3
How do you mass rename files from the command line? I have a bunch of mp3's with filenames like: Artist_-_Album_-_TrackNumber_-_Track_name.mp3 I want to convert all the "_"(underscore) to " "(space). ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2006
    Posts
    1

    Mass rename of files replacing '_' with space


    How do you mass rename files from the command line? I have a bunch of mp3's with filenames like:
    Artist_-_Album_-_TrackNumber_-_Track_name.mp3

    I want to convert all the "_"(underscore) to " "(space). I tried:
    $ for i in *; do mv "$i" `echo $i | tr '_' ' '`; done

    but it complains that:
    mv: target `name.mp3' is not a directory.

    What am i doing wrong?

  2. #2
    Just Joined! richiefrich's Avatar
    Join Date
    May 2006
    Location
    Houston
    Posts
    88
    I got's two you can try
    for i in ./*.mp3; do mv echo "$i" "${i//_/ }"; done
    if the output looks ok, remove the echo

    OR
    pipe this --> sed -e 's/ /_/'

    kinda like this
    find /mp3 -iname '*.mp3' -exec echo "$i" "`echo $i | sed -e 's/_/ /'" \;

  3. #3
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    Try:

    Code:
    $ for i in *_*; do mv "$i" "`echo $i | tr '_' ' '`"; done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •