Ubuntu – Concatenating several .mp3 files into one .mp3

bashcommand linefiles

As it was suggested here I am using cat command to concatenate several .mp3 files into one .mp3 file.

Imagine, I have following .mp3 files in the current folder:

001001.mp3 001002.mp3 001003.mp3 001004.mp3 001005.mp3

or, like this:

096001.mp3 096002.mp3 096003.mp3 096004.mp3

I need to concatenate these .mp3 files in there ascending sequence, i.e. 001001.mp3+001002.mp3+001003.mp3+etc.

In order to join these .mp3 files into one I am executing following command in the current folder:

cat *.mp3 > final.mp3

I tested the final .mp3 file and it is what I am expected, but I need to be sure that above command picks files in there ascending sequence.

Can I be sure that above command always concatenates files in the ascending sequence?

Thank you Sir!

Best Answer

cat is not the right tool for this job. The MP3 format has all sorts of junk that can lurk at the front and end of the file and this needs to be strippe out. mp3wrap is what you want. It will exclude any metadata in the files and stick the audio together.

sudo apt-get install mp3wrap
mp3wrap output.mp3 *.mp3

Before you do that, run ls *.mp3 to check that they're in the correct order. When I originally wrote this answer (over six years ago!) wildcard globs apparently didn't behave well but I think they do now.

You might need to rename the files if for example, they are numbered but aren't zero-padded, {1-11}.mp3 would be sorted by 1 10 11 2 3 4 5 6 7 8 9. This can be fixed easily.