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
sudo apt update
sudo apt install mpvThe following NEW packages will be installed:
mpv ...Risk level: caution. Review the command before running it.
Why mpv is the primary example
apt updaterefreshes package indexes andapt installchanges 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
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
--shufflerandomizes the internal playlist order.--no-videoprevents embedded cover art from opening a video window.--loop-playlist=infrepeats the full playlist; omit it for one pass.Quoting
$HOME/Musicpreserves 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
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, andxargs -0use NUL separators, preserving spaces, tabs, quotes, and embedded newlines.-ravoids 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
shufandxargs, which Ubuntu provides.
Create a reusable M3U-style playlist
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.m3uPlaying: ./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 sortmakes 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
sudo apt install mplayer
cd "$HOME/Music"
find . -type f -iname '*.mp3' -print > playlist.txt
mplayer -shuffle -playlist playlist.txtPlaying ./Artist/Track.mp3.
Audio only file format detected.Risk level: caution. Review the command before running it.
What the historical command actually does
-playlisttells MPlayer to read newline-delimited entries from the file.-shufflerandomizes its playback order.The pattern is quoted so
findevaluates 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.
9and0lower and raise volume.mtoggles mute andqquits.Run
mpv --input-keylistor consult the active manual because bindings can be customized.
Save preferences without a long command
no-video=yes
shuffle=yes
loop-playlist=inf
volume=70Use 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
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 GiBPreview catches a wrong root before it becomes noise
The first command samples matched paths without modifying files.
-printf %semits each file size andawktotals 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
fileandffprobeon the exact track; an.mp3extension 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-videoto 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
mpv stable manual documents
--shuffle, directory handling, playlists, looping, controls, and playlist security.Ubuntu mpv package search shows mpv availability in supported Ubuntu releases.
Ubuntu MPlayer package search confirms the historical player remains packaged.
Comments and corrections