Terminal music is wonderfully low-friction: no library scan, no account, and no interface between you and the album directory. The old two-command recipe almost works, but its newline playlist format can misread unusual filenames and its unquoted *.mp3 pattern is easy to expand in the wrong directory. We can keep the simplicity without keeping those traps.

Install a player from Ubuntu repositories

Ubuntu terminalbash
sudo apt update
sudo apt install mpv
The following NEW packages will be installed:
  mpv ...

Risk level: caution. Review the command before running it.

Why mpv is the primary example

  • apt update refreshes package indexes and apt install changes system package state, so review APT’s proposal.

  • mpv descends from MPlayer/mplayer2 and has a current, precise command-line manual.

  • Ubuntu distributes both mpv and MPlayer in the Universe component on supported releases.

  • Installation requires administrative privileges; playback itself does not.

Shuffle an entire trusted music directory

Ubuntu terminalbash
mpv --shuffle --no-video --loop-playlist=inf "$HOME/Music"
Playing: /home/user/Music/Artist/Track.mp3
 (+) Audio --aid=1 ...

One command creates the listening session

  • --shuffle randomizes the internal playlist order.

  • --no-video prevents embedded cover art from opening a video window.

  • --loop-playlist=inf repeats the full playlist; omit it for one pass.

  • Quoting $HOME/Music preserves spaces and wildcard characters in the directory name.

  • With current mpv directory behavior, shuffle causes recursive traversal; use an explicit playlist when you need exact filtering or order.

Play only selected audio extensions

Ubuntu terminalbash
find "$HOME/Music" -type f \
+  ( -iname '*.mp3' -o -iname '*.flac' -o -iname '*.ogg' -o -iname '*.m4a' ) \
+  -print0 | shuf -z | xargs -0 -r mpv --no-video --
Playing: /home/user/Music/Album/01 - First song.flac
...

This pipeline preserves arbitrary local filenames

  • The parentheses group extension predicates and must be escaped so the shell passes them to find.

  • Quoted patterns such as `*.mp3` are matched by find, not expanded early by the shell.

  • -print0, shuf -z, and xargs -0 use NUL separators, preserving spaces, tabs, quotes, and embedded newlines.

  • -r avoids launching mpv when no files match.

  • -- ends player option parsing, so a filename beginning with a hyphen is treated as media rather than an option.

  • This assumes GNU shuf and xargs, which Ubuntu provides.

Create a reusable M3U-style playlist

Ubuntu terminalbash
cd "$HOME/Music"
find . -type f ( -iname '*.mp3' -o -iname '*.flac' -o -iname '*.ogg' ) \
  -print | LC_ALL=C sort > local-music.m3u
mpv --shuffle --no-video --playlist=local-music.m3u
Playing: ./Artist/Album/Track.mp3
...

A text playlist trades robustness for portability

  • Relative entries remain portable when the playlist stays at the music-tree root.

  • LC_ALL=C sort makes generation deterministic before playback shuffles it.

  • A newline-separated playlist cannot faithfully represent a filename containing a newline.

  • Use this only for a trusted local playlist; playlists can reference URLs and special protocols.

  • mpv versions before 0.31 and MPlayer had weaker safety around malicious playlists, so never feed them random downloaded playlist files.

Keep the original MPlayer workflow when required

Ubuntu terminalbash
sudo apt install mplayer
cd "$HOME/Music"
find . -type f -iname '*.mp3' -print > playlist.txt
mplayer -shuffle -playlist playlist.txt
Playing ./Artist/Track.mp3.
Audio only file format detected.

Risk level: caution. Review the command before running it.

What the historical command actually does

  • -playlist tells MPlayer to read newline-delimited entries from the file.

  • -shuffle randomizes its playback order.

  • The pattern is quoted so find evaluates it recursively and case-insensitively.

  • Spaces are safe in a whole playlist line, but embedded newlines remain ambiguous.

  • Use MPlayer playlists only from trusted sources; mpv is the better default for a new workflow.

Useful mpv playback controls

  • Space pauses or resumes.

  • > advances to the next playlist entry and < returns to the previous one under standard bindings.

  • Left and right seek backward or forward; up and down make larger seeks.

  • 9 and 0 lower and raise volume.

  • m toggles mute and q quits.

  • Run mpv --input-keylist or consult the active manual because bindings can be customized.

Save preferences without a long command

~/.config/mpv/music.confini
no-video=yes
shuffle=yes
loop-playlist=inf
volume=70

Use a named profile instead of changing every playback

  • A separate config file avoids forcing music preferences onto video sessions.

  • Start it with mpv --include="$HOME/.config/mpv/music.conf" "$HOME/Music".

  • Command-line options can override configuration values for one session.

  • A fixed volume is a starting level, not protection against inconsistent mastering or hearing damage.

Inspect the playlist before playback

Ubuntu terminalbash
find "$HOME/Music" -type f -iname '*.mp3' -print | sed -n '1,20p'
find "$HOME/Music" -type f -iname '*.mp3' -printf '%s\n' | awk '{ total += $1 } END { printf "%.2f GiB\n", total/1024/1024/1024 }'
/home/user/Music/Artist/Track.mp3
...
12.34 GiB

Preview catches a wrong root before it becomes noise

  • The first command samples matched paths without modifying files.

  • -printf %s emits each file size and awk totals bytes.

  • The size estimate covers matching files, not decoded duration.

  • If zero files appear, check the directory, permissions, extensions, and mounted storage before blaming the player.

Troubleshoot silence and skipped tracks

  • No audio device: inspect pactl info, wpctl status, or the desktop sound settings for the active PipeWire/PulseAudio sink.

  • Permission denied: confirm execute permission on parent directories and read permission on the file; do not run the player with sudo.

  • Files with spaces break: quote shell paths and use the NUL-delimited pipeline for generated argument lists.

  • Unknown format or codec: run file and ffprobe on the exact track; an .mp3 extension does not guarantee MP3 content.

  • Playlist opens unexpected URLs: stop playback and audit the playlist; do not weaken unsafe-playlist protection.

  • Video window appears: add --no-video to suppress embedded artwork.

  • Shuffle feels repetitive: randomness can repeat artists; generate a curated playlist or use metadata-aware software for stronger sequencing constraints.

Primary references