Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
up vote 19 down vote accepted

Annoyingly *.mp3 is not guaranteed to preserve an order. I've been playing around with it and I've seen it pull back all sorts of different orders. Thankfully we can use ls and sort to fix this.

But cat is not the right tool for this job. mp3wrap is a better way of doing this. It will exclude any metadata in the files whereas cat will chuck it all in which might break things.

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

Check (with ls *.mp3) that they're in the correct order before you run this. If they aren't you might need to rename the files. If, for example, they are numbered but aren't zero-padded, 1-11 would be sorted by 1 10 11 2 3 4 5 6 7 8 9. This can easily be fixed.

share|improve this answer
Right - cat will mangle the mp3 file format by "creating an array" (as it were) of mp3 files within a single mp3 file. But it seems to work if the player software is smart enough. – user8290 Jan 8 '11 at 1:25
This worked better for me, because it handles mp3s with spaces in the filename: find . -maxdepth 1 -iname '*.mp3' -print0 | sort -z | xargs -0 mp3wrap output.mp3 – bmaupin Jul 31 '14 at 1:25
@bmaupin A fair point but I'm not sure why I wasn't just using Bash's wildcard expansion. *.mp3 should suffice (and works with spaces). – Oli Jul 31 '14 at 7:49
Available for mac from brew package manager! $ brew install mp3wrap. – Rubens Apr 4 at 16:14

As previously suggested, mp3wrap is a good solution. It may not work all of the time though. As far as I know, mp3wrap assumes that all the input files have the same characteristics such as VBR vs CBR, bitrate, and so on. If this assumption isn't met, it is likely to fail. In that case, the only solution would be to decode all the mp3files to a raw format like .wav, concatenate them with a program like sox and finish by re-encoding all to mp3.

share|improve this answer

mp3wrap seems to be a decent enough solution, but when I played the resulting file, the timestamp wasn't correct. It seems like mp3wrap is best used when you're joining mp3s into a file that you know you'll want to split later.

I simply wanted to permanently concatenate some mp3s together. I ended up using ffmpeg to concatenate the files:

  1. First, install ffmpeg (ubuntu doesn't include it any more) by going to, download one of the static builds, untar it, and copy to /usr/local/bin
  2. ffmpeg -i "concat:file1.mp3|file2.mp3" -acodec copy output.mp3

More info:

share|improve this answer
ffmpeg is missing, but avconv replaces it:… – muru Jul 31 '14 at 2:00
Yeah, I used avconv for a while, but then I needed some features that ffmpeg had and avconv didn't, and I haven't used it since. These days it feels like a waste of time checking to see if avconv has the features I need when I already know ffmpeg does. – bmaupin Jul 31 '14 at 13:05
Please feel invited to join this bug report discussion. – orschiro Jan 25 at 8:41

It does an alphabetical sort based on single characters. That means that "01" comes before "1", since nought has a lower value than one.

Here's an example. I've got a directory with files named 1, 2, 3, 04, 05, and 06. They are text files that contain their own file names:

test$ cat *

So, yes it will; but you need to make sure that all your files are 'padded' properly.

This nifty line of bash script will let you visually compare the file names, making it very easy to spot any mistakes:

for f in $(ls); do printf "%05s\n" "$f"; done

It's output will look like this:


If they aren't, you will need to pad the file names: Bash script to pad file names on StackOverflow explains how to do it.

Edit. Vote for Oli's answer, it's much better. :P
I'll leave mine because it add something, but you should use his solution,

mp3wrap output.mp3 `ls -1 *.mp3 | sort`

Keep in mind that sort will still sort things in the way I described above, you will still need to pad file-names if they aren't equal in length.

share|improve this answer

You might wanna try using a dedicated audio editing program (like Audacity)

share|improve this answer

I found the online service audio-joiner to work very well and preserve the correct time-stamp (contrary to mp3wrap).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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