1. Introduction

MP3 tags, also known as ID3 tags, are metadata embedded within MP3 audio files. These tags contain information about the audio file, such as the song title, artist, album, genre, year, and other details.

In this tutorial, we’ll learn how to get MP3 tags in the Linux command line.

2. Using id3v2

id3v2 is a tool for working with MP3 tags in Linux that enables us to view, edit, and manipulate ID3 tags within MP3 audio files.

First, let’s install id3v2 via apt-get and sudo:

$ sudo apt-get install id3v2

Once installed, we can view the tag information of an MP3 file:

$ id3v2 -l music.mp3
id3v1 tag info for music.mp3:
Title  : Paria                           Artist: Avang Music                   
Album  : Dariush                         Year: 1991, Genre: Other (12)
Comment: Record label                    Track: 1

In this case, we used -l to list the tags on the file. As a result, we can see the metadata such as Title, Artist, Album, and more stored within the ID3 tags of the MP3 file.

3. Using eyeD3

eyeD3 is a command-line tool and Python library for working with audio files, particularly MP3 files. Hence, it’s designed to enable users to manipulate and manage the metadata embedded within MP3 audio files.

First, let’s install eyeD3:

$ sudo apt-get install eyed3

Now, we get the tag information of an MP3 file:

$ eyeD3 music.mp3
/home/amir/music.mp3                                                         [ 10.44 MB ]
------------------------------------------------------------------------------------------
Time: 04:19    MPEG1, Layer III    [ 320 kb/s @ 44100 Hz - Stereo ]
------------------------------------------------------------------------------------------
ID3 v2.4:
title: Morning Moon
artist: Happy Prescriptions
album: Lights E.P.
album artist: Happy Prescriptions
recording date: 2017-03-03T19:06:58
track: 3        genre: Rock (id 17)
Comment: [Description: ] [Lang: eng]
...

------------------------------------------------------------------------------------------

In this instance, the output displays detailed information about the audio file, including its technical specifications and the metadata contained within the ID3v2.4 tags.

4. Using exiftool

exiftool is a powerful tool for reading, writing, and editing metadata in a wide range of files, including MP3 audio files. While it’s known for its capabilities with image files, it can also handle audio formats, making it a versatile tool for working with MP3 tags in the Linux CLI.

To begin with, let’s install exiftool:

$ sudo apt-get install exiftool

Then, we can use exiftool to get information about the MP3 tags:

$ exiftool music.mp3
ExifTool Version Number         : 12.40
File Name                       : music.mp3
...
Audio Bitrate                   : 320 kbps
Sample Rate                     : 44100
Channel Mode                    : Stereo
MS Stereo                       : Off
Intensity Stereo                : Off
Copyright Flag                  : False
Original Media                  : False
Emphasis                        : None
ID3 Size                        : 601256
Title                           : Morning Moon
Artist                          : Happy Prescriptions
Track                           : 3
Album                           : Lights E.P.
...

Evidently, exiftool provides a wide range of information about MP3 tags.

Moreover, we can view the tag information of multiple MP3 files in the same directory:

$ exiftool *.mp3

In this case, we display the tag information for all MP3 files with the .mp3 extension in the current directory. Here, we use a wildcard character * to process them all at once.

5. Using ffmpeg

ffmpeg is a framework that includes a powerful command-line tool for handling audio and video files. While it’s mainly known for audio and video processing, it can be used to extract and manipulate metadata from audio files.

First, let’s install ffmpeg:

$ sudo apt-get install ffmpeg

Then, we get information about the audio file:

$ ffmpeg -i music.mp3
...
Input #0, mp3, from 'music.mp3':
  Metadata:
    title           : Morning Moon
    artist          : Happy Prescriptions
    track           : 3
    album           : Lights E.P.
    date            : 2017-03-03T19:06:58
    genre           : Rock
    copyright       : Attribution-Noncommercial-No
    TDAT            : 2017-03-03 19:06:58
    comment         : URL: http://freemusicarchive.org
                    : Comments: No-comments
                    : Curator:
                    : Copyright: Attribution-Noncommercial-No
    album_artist    : Happy Prescriptions
...

Here, the output shows the metadata information of the MP3 file and more details.

Of course, we can also use ffprobe, which is part of the FFmpeg package:

$ ffprobe music.mp3

Here, the output matches the one obtained with the previously used ffmpeg command.

6. Using lltag

lltag is designed for tagging and renaming audio files in a flexible and automated manner. Hence, we can manage the metadata of audio files, making it a handy tool for organizing audio files.

First, let’s install lltag:

$ sudo apt-get install lltag

Now, let’s see how we can use lltag to get MP3 tags:

$ lltag -S music.mp3
  ARTIST=Happy Prescriptions
  TITLE=Morning Moon
  ALBUM=Lights E.P.
  NUMBER=3
  GENRE=Rock
  DATE=2017-03-03T19:06:58

In this case, the output displays MP3 tags. Here, we used -S to specify show tags.

7. Using perl

perl is known for its powerful text processing capabilities, making it a suitable choice for extracting metadata from MP3 files. We can use the MP3::Tag module to retrieve MP3 tags programmatically.

First, let’s install libmp3-info-perl:

$ sudo apt-get install libmp3-info-perl

Then, let’s see how we can use perl to get the metadata of an MP3 file:

$ perl -MMP3::Tag -E 'say MP3::Tag->new("music.mp3")->artist'
Happy Prescriptions

As we can see, the output shows the artist’s name from the metadata.

Let’s break down the script above:

  • -MMP3::Tag tells perl to load the MP3::Tag module
  • -E tells perl to execute the code provided in single quotes as a one-liner
  • say prints the value of the artist tag to the console
  • MP3::Tag->new(“music.mp3”) creates a new instance of the MP3::Tag module, opening the music.mp3 file in the process
  • ->artist accesses the artist tag information from the opened MP3 file

In summary, this script loads the MP3::Tag module, opens music.mp3, retrieves the artist tag, and then prints the artist’s name to the console.

8. Conclusion

In this article, we’ve explored several command-line tools, unlocking the ability to check audio file metadata, maintain its consistency, and expand our general technical expertise within the Linux environment.

On this Linux audio file management journey, we’ve learned command-line tools like ID3v2, eyeD3, exiftool, ffmpeg, lltag, and perl to explore our audio files.