Bash - Set MP3 filename as the song title

By xngo on June 17, 2019

  1. You have to install id3v2.
    aptitude -y install id3v2
     
  2. Run the following script in directories that contain MP3 files.
    #!/bin/bash
    # Description: For each MP3 file, set the filename as the song title
    for i in *.mp3; do
      SONG="$i"
      id3v2 --song "$SONG" "$i"
    done
     
  3. Or add also the order number in the comment.
    #!/bin/bash
    # Description: For each MP3 file, set the filename as the song title and add the order number in the comment.
    idx=1
    for i in *.mp3; do
      SONG="$i"
      id3v2 --song "$SONG" --comment "${idx}" "$i"
     
      let idx=idx+1
    done
     

Layout of ID3v1

Field Length Description
header 3 TAG
title 30 30 characters of the title
artist 30 30 characters of the artist name
album 30 30 characters of the album name
year 4 A four-digit year
comment 28 or 30 The comment
zero-byte 1 If a track number is stored, this byte contains a binary 0.
track 1 The number of the track on the album, or 0. Invalid, if previous byte is not a binary 0.
genre 1 Index in a list of genres, or 255

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.