-   Linux - General (
-   -   Bash script to set title of MP3 file equal to name of MP3 file (

jwbales 07-10-2012 02:48 PM

Bash script to set title of MP3 file equal to name of MP3 file
I bought a tutorial to help me learn a foreign language and want to put the lessons on my ipod. However, none of the hundreds of mp3 files have any tag information. I was able to use eyeD3 to name the artist and album on all the files in batch mode, but none of the files has a title. So when I loaded them into my ipod, no titles are visible. Since the file names are of the form lesson001.mp3, lesson002.mp3, etc, the filenames are ok to use as titles. But how do I do some sort of batch command to place the filename into the 'title' field of the tag? I'm sure there is some simple way to do this using a bash script, but it's been decades since I wrote a bash script. Help!

Kustom42 07-10-2012 03:16 PM

It can more than likely be done via BASH but I am not familair enough with how the meta-data is setup for the file title etc.. I'll do some searching on that and see if I can help. I'm sure someone else here knows more about the way the mp3 files retain that data and may be able to help more directly but I'll see what I can find.

jwbales 07-10-2012 05:04 PM

This is what I tried, but although it echoed the proper commands, it did not actually perform the commands and no changes were made in the id3 tags of the mp3 files.

for x in `ls`; do echo "eyeD3 --title='$x' file $x"; done

Kustom42 07-10-2012 05:14 PM

remove the echo, your not telling the system to execute the eyeD3 command, just to echo it. I was finding similar info and was about to post a similar for loop.

jwbales 07-11-2012 12:17 AM

Yes, thank you, removing the echo helped, but the script still failed. Eventually I figured out how to use EasyTag to accomplish the task.

evo2 07-11-2012 12:42 AM


also you should replace youtr `ls` with *. Also the "file" should not be there. Ie


for x in * ; do
  eyeD3 --title="$x" $x

Finally, you might like to strip the filename extension from the title.

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



sazary 09-15-2013 02:19 PM

if your file names have spaces (like my files!) you should change 2nd line to:


  eyeD3 --title="${x%.*}" $x

Dafydd 09-15-2013 10:20 PM

Here is a script I use.


##use 'mp3info' to insert data tags in 'mp3' files.

# check if there is no command line argument
if [ $# -eq 0 ]
echo "You forgot the information."
echo "This is only for 1 albun name and 1 artist."
echo "3 fields are required artist, album, genre, in that order."
echo "Either no spaces in each field or use quotation marks around each field."


for filename in *mp3;  ##list all mp3 names in directory

  if [ -f "$filename" ]
                mp3info -t "$song_name" -a "$artist" -l "$album" -g "$genre" "$filename";

All times are GMT -5. The time now is 03:38 PM.