Has anyone got a bash script that will go through a media library and set the id3 title tag of each MP3 file to be equal to the file's name?

I'm open to other automated methods too. It can be a GUI application or anything that will do the job automatically.

An EasyTag method is noted here: How to rename bulk title tag in mp3 ID3 files — Unfortunately, I don't understand the steps.

  • You may answer your own question. List the steps you found on ubuntuforums.org and cite your source. :) This will help future visitors to Superuser, in the case that the ubuntuforums.org link becomes unavailable.
    – iglvzx
    Mar 9, 2012 at 4:45
  • 3
    Here are a few tips: 1) Don't clutter your question with "edit 1", "edit 2", etc. Resolve problems using comments. 2) If you find a solution, post it as an answer, as if you were trying to answer someone else's question. Don't put the answer into the question. That's not where people look for it :) Also, use blockquotes for anything you quote from somewhere else (see the formatting help).
    – slhck
    Mar 9, 2012 at 8:34
  • I made a script to correctly tag MP3 files in the format "Artist - Track.mp3" and then rename the file to "Track.mp3": gist.github.com/ZachSaucier/f51e608ac75e8ed6e96cd54a9ec103b0 using eyed3 Nov 16, 2019 at 1:07

8 Answers 8


EasyTAG is indeed a great tool for this problem. I found my answer here. In terms of how to use it, the best reference turns out to be EasyTAG’s own documentation.

Open EasyTag, navigate to a folder with music files in it, select all the files in the folder, or all the files you want to tag, click on the "Scan Files" button (you'll have to hover over them to figure out which one it is).

Then, make sure the scanner dropdown is set to "Fill Tag," then in the Fill Tag field, make the appropriate edits until the example below the field looks like what you're looking for. If you need further help as to what to put in the Fill Tag field, click on the "?" button for the legend (listing of what the different possible codes are to translate with) and hit the mask button to list some starting points.

When you're happy with the results, click the "Scan Files" button (in the Scan Files dialog box, not the one you originally clicked to get where you are...the icons look the same) and your changes will be applied. If you are not getting Artist or Album name, simply select all that you want to change, enter the data and click the little button next to that field and all files that are selected will the filled in or changed to that artist or album. This works in most fields.

When you're done, click the save button and you're done.

PS: The CDDB scanner often works pretty well, if you have full albums that you're trying to tag, or at least commercially available song files.

PPS: I am apparently half awake still. According to what you wrote in your original post, try this in the Fill Tag field:

%n. %a - %t

Here's the section that is relevant to this question:

1.2.2. Automatically with “Fill Tag” scanner:

Some conditions to use this mode:

  • files sorted by albums
  • filenames or parent directory contain tag information (artist, album, title, …)
  • empty or not correct tags

The “Fill Tag” scanner uses a pattern to associate words in the filename and directories with the tag entries. By this way, the tag fields can be completed automatically by pressing the “green” button in the scanner window or the toolbar. If the tag is partially completed, use the option “Overwrite fields when scanning tag” in the “Scanner” tab of the “Preferences” window, to replace all fields by the new values.

Each code correspond to a field, following theses rules :

Strings associated with code    Will fill the field
  Encoded by
  None! (used to ignore a string)
  Number of tracks
  Original artist

Note : to avoid mistakes, it is recommended to use a code only one time in the pattern. Of course, like when tagging manually, only the selected files are processed by the scanner. You can use the defined patterns in the list, or write yours own patterns to correspond to the format of yours file names and directories. To avoid mistakes when selecting the right pattern, or writing it, a preview shows immediately the results before to apply the pattern. If you need some help with the different codes, press the “Help” button (the lifebuoy) to display the legend of each code. Also, if you want to save yours own patterns, edit or sort then, by pressing the “Mask” button an little editor will be shown on the scanner window.

Below an example of use of patterns :

a) the following filename :

“/mnt/MP3/EVANESCENCE – Fallen (2003) – Rock/01. Going Under.mp3”

b) with the pattern :

“%a - %b (%y) - %g/%n. %t”

c) you will fill the tag with theses strings :

    Artist (%a) => EVANESCENCE
    Album (%b) => Fallen
    Year (%y) => 2003
    Genre (%g) => Rock
    Track (%n) => 01
    Title (%t) => Going Under

EasyTAG does all sorts of common batch tag/filename operations on audio (and some video) files.


I have found a variety of command line tools to be useful:


id3v2 is a command line id3v2 tag editor. You can add/modifiy/delete id3v2 tags and convert id3v1 tags to id3v2 tags. It's uses id3lib. I'm looking for a co-maintainer. Please email myers_carpenter if you are interested.


eyeD3 is a Python module and program for processing ID3 tags. Information about mp3 files (i.e bit rate, sample frequency, play time, etc.) is also provided. The formats supported are ID3 v1.0/v1.1 and v2.3/v2.4.

these are ideal when scripting something to scan directories.


This doesn't always get it exactly perfect, but I have used it to get the names of mp3 files using only common unix tools (including the busybox versions) Perhaps someone with more than just 6 Tom Petty mp3s can give it some further testing.

for x in *.mp3; do
  TITLE=$(strings "$x" |grep TAG |grep -v TAGL |sed "s/^.*TAG//g ; /^L$/d ; /^@$/d ; /^$/d ; /^Ac$/d")
  #mv "$x" "$TITLE.mp3"
  echo $x" "$TITLE.mp3" #just echo for now, until further tested

Edit: I misread the question, but knowing this above we can use sed to replace $TITLE with the name of the file "$x" by using sed to replace the string in place

sed -i "s/$TITLE/$x/" "$x"

I am almost 100% sure this does not meet all of the ID3 spec, but it may suffice for basic personal use as long as you make a backup first

  • Thanks. I found a way to accomplish my goal using EasyTAG, but your reply actually answers my original question best. strings is a good utility to know about. (I haven't used it before.) Could you post a complete solution based on your edit so I can be sure I understand the suggested change?
    – MountainX
    Mar 13, 2012 at 20:31

For Ubuntu 18.04 LTS (I assume all Debian flavors will run this just fine):

  • Install eyeD3 with sudo apt install eyeD3

  • Create a file for bash script (I used "touch"; you can use whatever text editor you like)

  • Copy this and paste it into file:

    Copies file name and writes it to the Title tag

    for x in *; do
        eyeD3 --title="${x%.*}" "$x"
        echo $a

    If you don't care to view the progress, omit the line echo $a above the word "done".

  • Make the file executable:

    chmod +x filename
  • Copy the script to the directory you want it to run in – the one containing your media files; for example:

    cp filename /music/directory
  • Navigate to the directory you just copied the script to:

    cd /music/directory
  • Run the script:



It worked for me on Ubuntu 18.04 LTS – my wife wrote this for me in about 3 minutes, so I can't answer any questions if it doesn't work for you; I am not programmer savvy, I am setup this web, dns, ssh,sftp,ftp,AD/Domain, file,firewall,router/server kinda guy:-) I HATE doing scripting, programming and anything like it. I LOVE taking advantage of scripting, programming and anything like it:-)


I am surprised that no one has suggested the easiest solution using ffmpeg or avconv:

for i in *.mp3; do avconv -y -i "$i" -c copy -metadata title="$i" new_"$i"; done;

I would install eyeD3 in a python virtualenv with pip install eyeD3 so you get the most recently released version. After that run:

for i in *.mp3; do /your/venv/bin/eyeD3 --title "$i" "$i"; done

I have upvoted shivams answer since I did not have to install any additional dependencies and the solution worked perfectly as a oneliner. Have used ffmpeg + libav a lot in the past. I'd like to add an improvement but have too few reputation points, so I'll add it as an additional answer.

The above version leaves the ".mp3" ending in the title and renames all the files with a prefix in front. I here provide a solution that saves all the files in a subfolder (make sure to create it first) and drops the last 4 chars of the filename. Voilà:

for i in *.mp3; do avconv -y -i "$i" -c copy -metadata title="${i%????}" new/"$i"; done;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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