Mplayer Shuffle Command: Play Files In Random Order

How do I play files in random order using the mplayer command line player under Linux / Unix operating systems?

You can play most files such as MPEG/VOB, AVI, ASF/WMA/WMV, RM, QT/MOV/MP4, Ogg/OGM, MKV, VIVO, FLI, NuppelVideo, yuv4mpeg, FILM and RoQ files in random order using the following command syntax:

mplayer -shuffle -playlist YOUR-PLAY-LIST-HERE
# for small playlist #
mplayer -loop 0 -shuffle $(cat your_playlist.m3u)


  • -loop 0 : Loops movie/music playback N times. 0 means forever.
  • -shuffle : Play files in random order
  • -playlist : Play files according to a playlist file. Do NOT use -playlist with random internet sources or files you don’t trust!

How Do I Generate a Playlist?

The mplayer can play files according to a playlist file type such as ASX, Winamp, SMIL, or one-file-per-line format. You can use the find command to generate a playlist for mplayer:
$ cd /path/to/music/dir
$ find -type f -iname \*.mp3 > playlist.txt

mplayer Shuffle Mode Command

Type the following command:
$ mplayer -shuffle -playlist playlist.txt

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 21 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
21 comments… add one
  • Dougle Oct 2, 2011 @ 14:36

    Hey look! it’s the bottom of the barrel! I wondered when we would run out of linux commands.

  • collin Oct 10, 2011 @ 19:50

    Open a terminal and cd to the directory that has the music files you want to play. next type “mplayer *.*” press enter. Enjoy!!!!

  • ari Nov 4, 2011 @ 6:50

    Now, what if i want to skip to the next song? what is the shortcut?

    • ari Nov 4, 2011 @ 6:56

      no problem, press enter will bring me to the next song.
      Thank you :D

  • Dinesh Mali Dec 12, 2011 @ 18:30

    Great tips!! Thanks for this beautiful post

  • joshua Jan 3, 2012 @ 9:13

    how do I enqueue another song while one is already playing?

  • Leo Jun 24, 2012 @ 16:35

    If only I had found this post earlier…
    Great post! Thanks!

  • donatom Jul 7, 2012 @ 18:01


    I have been wondering how to do what you so wonderfully explained for many years!
    Thanks for your help — and thanks for helping the whole Linux/Gnu community!

  • know all Oct 22, 2012 @ 14:54

    ‘mplayer *’ will do. Perhaps *.* is a relic from dos times :)

    • Joshua Oct 23, 2012 @ 0:37

      relic, lol, I miss dos.. Found another one tho! mplayer */* for your whole collection, it will do all in this directory, and all in one directory down.. I’ve also used mplayer */*/* to play two folders down.. =]

  • PJ Brunet Jan 8, 2013 @ 18:49

    I bet there’s a way to do this without making a playlist.

  • Anonymous Mar 30, 2013 @ 3:08

    Seems to work with regular filelists, e.g. mplayer -shuffle * will play files in the current directory in a random order.

  • PJ Brunet Mar 30, 2013 @ 19:22

    Thanks Anonymous, that works for me!

  • un Jul 5, 2014 @ 22:25

    i am actually almost disturbed at the amount of people praising this advice.
    so, on the one hand you have this simple idea of composing a command for terminal, BUT then you HAVE TO THEN ADD THE WHOLE BLOODY PLAYL;IST THAT YOU HAVE ALREADY GOT IN YOUR PLAYER?
    how impractical and long winded is that?
    stupid idea. really dumb.
    and to cut a long story short:
    WHERE IS THE BLOODY RANDOM/SHUFFLE BUTTON? (like any sensible decently designed player has)

    • Joshua Jul 7, 2014 @ 5:12

      not our server at work, no GUI.. plus on top of that, each employee has their own music folder, so depending on who’s working, is who has control over the music server via SSH.. so no buttons, except the ones at the keyboard, and no mouse control.. period..

      • Joshua Jul 7, 2014 @ 5:17

        but it’s cool man, we let it slide for noobs around here; because, everyone “praising” this post, can tell that you’ve never used a terminal before.

  • Lindylex Feb 4, 2015 @ 20:33

    This should work also.
    mplayer -shuffle -loop 0 *.mp3

  • bertrand Apr 12, 2016 @ 9:42

    If I understand correctly the several comments in this post, it is not possible to remove the -shuffle when we are in slave mode?
    By example, I have start mplayer in slave mode, I currently have script to “loadlist toto.m3u >/tmp/my.mplayerontroller” and I want to add the option to play my playlist with our without shuffle.
    Will I have to kill mplayer and restart it to achieve this? or is there a slave mode command like “shuffle true >/tmp/my.mplayerontroller”

  • Jerry Jun 15, 2016 @ 4:15

    MPlayer shuffle is not random at all. I know good random generators are not trivial to make, but there are good, free solutions out there. This is really getting irritating. After using it for a while, I can predict which folder it will visit, which also means the mplayer RNG does not cover all the files.

  • Paul Mar 1, 2021 @ 19:16

    There’s a big difference between random, and just not in alphanumeric order. Many music players do not randomize playlists. E.g. I have my alt-indie playlist (tested in m3u & pls) with 1522 songs in it. But when I click its desktop icon to start, mPlayer always starts at the first song in the playlist, then song # 135, then song # 27, the song #288, and so on (these are just made up numbers). In other words, it does not start off with song # 88, then another completely random number after it, and so on. It always plays in order, the same sequence of songs. I know this because, even though it’s a huge playlist, I hear the same 4 dozen songs, over and over, everyday. In a truly random scenario, I should not hear the same song twice inside of half a year! But fear not: VLC does random playback!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum