Playing Music in Bash With Mplayer and Find Command

iconHere’s a quick way to play music from bash shell, or sort of having your own simplified media player with the find command and mplayer. For this open a shell and cd into you music folder, and simply use the find command to enter the artist name, and pass it to mplayer so it loops through all the songs it finds. The commands it is very simple.

find . -name "artist name" -exec mplayer '{}' \;

but what if you don’t know the exact name of artist or name of the song, but a portion of the string in title. Well, simply just use regular expression “*” asterisk.

find . -name "*artistname*" -exec mplayer '{}' \;

And in case you don’t know whether the name is with capital letter or lower case use -iname. This one will play all songs containing “pink floyd” regardless of capitalization or not.

find . -iname "*pink floyd*" -exec mplayer '{}' \;

In case that you have pictures, movies and songs that contain same string like “pink floyd” you could search by extension eg: mp3

 find . -iname "*pink floyd*.mp3" -exec mplayer '{}' \;

If you just want to play all mp3 files you’ve got in the folder

 find . -name "*.mp3" -exec mplayer '{}' \;

and here are some very useful keyboard shortcuts to navigate mplayer from the command line
p / SPACE Pause (pressing again unpauses).
q / ESC Stop playing and quit.
/ and * Decrease/increase volume.
9 and 0 Decrease/increase volume.
m Mute sound.
< and > Go backward/forward in the playlist.
ENTER Go forward in the playlist, even over the end.
Here you can download a cheat-sheet of mplayer keyboard shortcuts

Share This!

1 thought on “Playing Music in Bash With Mplayer and Find Command

  1. Paul Cooklin

    Thanks for this but Im getting:
    MPlayer 1.2.1 (Debian), built with gcc-5.3.1 (C) 2000-2016 MPlayer Team
    mplayer: could not connect to socket
    mplayer: No such file or directory
    Failed to open LIRC support. You will not be able to use your remote control.

    Playing ./2-09 On GP.mp3.
    File not found: ‘./2-09 On GP.mp3’
    Failed to open ./2-09 On GP.mp3.

Leave a Reply

Your email address will not be published.