Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I tried to open all my .mp3 files from a folder using xdg-open but I found out it opens just one! So I searched a little but there was not such a question! I found "evince" but apparently it open text files and gnome-open also opens one file.

I want to open all files of the same format in a folder from the terminal. I'm new to Ubuntu so please explain a little more.

share|improve this question

4 Answers 4

Indeed. You could use shell to get around this, like this:

ls -b *.mp3 | xargs -n 1 xdg-open

Or, if you want it more robust, try

find -iname '*.mp3' -print0 | xargs -0 -n 1 xdg-open
share|improve this answer
The first doesn't work with files with whitespace in their name, and the second doesn't work at all (find: paths must precede expression: -). –  Sparhawk Oct 24 '13 at 13:22
If you read carefully, I wrote "if you want it more robust...", hence the first, simple version doesn't work with spaces indeed, but that was not the intention. The second solution does work with ubuntu; FYI, newer versions of find default the pathname to . –  Agoston Horvath Oct 25 '13 at 14:29
I'm not sure that the lack of path is the problem in the second (despite the error message). I tried putting in . and got the same error message. In another directory, I get xdg-open: unexpected argument './foo.mp3' with or without .. –  Sparhawk Oct 25 '13 at 22:33
Also, I think that having spaces in names is not so uncommon a scenario that it should be disregarded, even in "simple" cases. –  Sparhawk Oct 25 '13 at 22:41
I don't know enough about your specific setup to say for sure, but xdg-open works as I described on a new ubuntu install. See man xdg-open if unsure. –  Agoston Horvath Oct 27 '13 at 16:06

You can try:

ls *.mp3 | while read -r file; do xdg-open "$file"; done

ls *.mp3 wil list all mp3 files from the current directory, each one on its own line, and the output is piped to an while loop witch read the content of each line and it will open that content (which is the name of a mp3 file in this case) in its default application.

share|improve this answer
@karel I added the -r flag. I think this is necessary to correctly parse files with a `\` in their name. –  Sparhawk Oct 26 '13 at 1:13
umm... wont this open several instances of the same program? –  Braiam Oct 26 '13 at 1:38
@karel Yeah… my man read doesn't have any flags listed at all, too! I don't get an error in my testing, but that's probably because I created aaa and aa\a. In this case, xdg-open just tries to open aaa twice, and not aa\a. (Okay, it's getting a bit convoluted, but I think code should work for all situations. Perhaps find is a better option, to avoid the limitations of ls and read.) Also, how can it wreak havoc exactly? Isn't it only going to parse the output of ls? –  Sparhawk Oct 26 '13 at 2:06
@karel man read is reffering to the C function read (section 2 of the man). This read is a bash builtin command, so you should look in man bash somewhere at line 4632. @Sparhawk - thanks for edititng. –  Radu Rădeanu Oct 26 '13 at 7:00
@Braiam umm... this is not the case for mp3's and depends about the settings from the default application. The behavior is the same like when you open multiple files from Nautilus or your favorite file manager. –  Radu Rădeanu Oct 26 '13 at 7:28

You can use these commands

cd /path/to/source_folder

find . -type f -name *.mp3 -exec vlc {} \+

only if your music player supports multiple files as command line arguments. Replace vlc with your music player of choice.

This works with RhythmBox and VLC in my testing.

share|improve this answer
Doesn't find...-exec run individual commands on each file? And also, if your music player supports multiple files as command line arguments, you could just use vlc *.mp3. –  Sparhawk Oct 27 '13 at 22:59

Use this command for mp3 files if you want to open files in VLC.

vlc /directory/*.mp3

Note: Use cvlc to use VLC without interface.

share|improve this answer
The question says "default program", so using VLC directly is a bit... pointless. –  muru Sep 28 '14 at 5:14

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.