How to play MP3 by command line in Linux

Ever wondered if it's possible to play music from your Linux Terminal? That's the topic today! Let's show you various ways to play the MP3 audio files by command-line.

The Linux Terminal is one of the most powerful and reliable utilities one can get hands-on. You can use it to install packages and applications, execute programs, solve arising system issues, etc. But what would be more captivating than being able to play your mp3 music from the Terminal? Other than refreshment, there are situations where the Terminal is all you have to perform your tasks.

In this post, we will show you the various ways you can use to play your music from the command-line in Linux.

Play MP3 music via Command-Line

To get started, we will need to use several tools, most of which don’t come pre-installed. However, this shouldn’t worry you as we will give a detailed guide on how to install them in various Linux distributions

VLC to play mp3 music in command-line

VLC is one of the best and most popular media players. It supports a wide range of video and audio formats, making it the right choice for this post. However, we will not use the VLC – GUI (Graphical User Interface); instead, we will use the nvlc tool, the Ncurses interface of the VLC application.

Installing VLC in Ubuntu:

sudo apt update
sudo apt install vlc

To play an mp3 file in the command-line, launch the Terminal and execute the command below:

$ nvlc <file-name>
e.g.;
$ nvlc music-file.mp3

nvlc utility
nvlc utility

The Ncurses interface will open in the Terminal, and the mp3 file will start playing. You can even monitor it in the progress bar.

nvlc Ncurses interface
nvlc Ncurses interface

Like the VLC-GUI player, nvlc also comes with several control buttons ensuring you have an excellent experience. You can use Spacebar to pause your music and Left/Right arrow keys to forward or rewind your music.

If you have a directory full of music, you can play the entire playlist with the command below:

$ nvlc <path-to-your-directory>
e.g.,
$ nvlc /home/tuts/Desktop/MUSIC

nvlc to play Playlist
nvlc to play a playlist

The Ncurses window will open, showing your whole playlist.

Playlist
Playlist

Another VLC utility you use to play your music in the command line is cvlc. However, unlike nlvc, cvlc is simple, less verbose, and doesn’t use the Ncurses interface. To play a song with cvlc, execute the command below:

cvlc music-file.mp3

cvlc
cvlc

From the image below, cvlc is simple and lacks many exiting features.

cvlc dummy interface
cvlc dummy interface

MPG123 to play mp3 music using the command-line

Another popular utility for playing mp3 music in the command-line is mpg123. Unlike VLC, mpg123 comes pre-installed in several distributions. However, if it is not available for you, follow the steps below:

Install mpg123 in Ubuntu:

$ sudo apt update
$ sudo apt -y install mpg123

Install mpg123 Fedora:

$ sudo dnf install snapd
$ sudo ln -s /var/lib/snapd/snap /snap
$ sudo ln -s /var/lib/snapd/snap /snap

mpg123 comes with a lot more options that you can use. Execute the command below to see all of them.

mpg123 --help

mpg123 help command
mpg123 help command

To play an mp3 file using mpg123, execute the command below:

$ mpg123 music-file.mp3

mpg123 play music
mpg123 play music

To play all mp3 files in a directory, navigate to that particular directory using the Terminal and run the command below:

mpg123 *.mp3

mpg123 playlist
mpg123 playlist

Alternatively, you can shuffle your playlist with the -Z option. See the command below:

mpg123 -Z *.mp3

mpg123 shuffle songs
mpg123 shuffle songs

To view the entire list of all options, you can use with mpg123 utility, use the –longhelp command as shown below:

mpg123 --longhelp

FFplay

FFplay is a built-in media player that comes with the FFmpeg media tools. FFmpeg is a powerful utility used not only to play media files but also to perform other numerous tasks. It doesn’t come pre-installed but is available for most Linux distributions.

Install FFmpeg on Ubuntu:

sudo apt update
sudo apt install ffmpeg

Install FFmpeg on Fedora:

sudo dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf -y install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
sudo dnf -y install ffmpeg
sudo dnf -y install ffmpeg-devel

To play your mp3 file in the command-line with ffplay, execute the command below;

ffplay music-file.mp3

Your music will start playing, but you will see a GUI window pop-up display the spectrum analyzer.

ffplay spectrum window
ffplay spectrum window

If you don’t wish to have the spectrum analyzer window, include the -nodisp option in your command.

ffplay -nodisp music-file.mp3

ffplay show nodisplay
ffplay nodisplay

Like any other Linux tool, the ffplay comes wit a set of options that you can use while playing your music. You can see these options with the –help command.

ffplay --help

For example, if you don’t want ffplay to display the build config and license information banner, use the -hide_banner argument.

ffplay -nodisp -hide_banner music-file.mp3

ffplay hide banner
ffplay hide banner

Mplayer to play mp3 music on the command-line

Mplayer is another excellent utility we can use to play mp3 files in the Terminal. Even though this tool doesn’t come pre-installed, it is available for most Linux distributions. It also supports several control functions like the Spacebar for pause/play, Left/Right arrow keys to forward or rewind your music.

Install mplayer on Ubuntu:

$ sudo add-apt-repository universe
$ sudo apt update
$ sudo apt install mplayer MPlayer-gui

Install Mplayer on Fedora:

$ sudo dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
$ dnf install mplayer

To play an mp3 file in the background with Mplayer, execute the command below:

mplayer music-file.mp3

mplayer
MPlayer

If you have a directory full of mp3 files, you can play them with the *.mp3 command.

mplayer *.mp3

mplayer playlist
MPlayer playlist

If you are playing an extensive playlist, it would be nicer if you could shuffle through the list. Include the -shuffle flag in your command.

mplayer -shuffle *.mp3

mplayer shuffle
MPlayer shuffle

You can also repeat a single song as many times as you wish with the -loop argument. The command below will repeat that particular song 25 times.

mplayer -loop music-file.mp3

mplayer loop
MPlayer loop

Other essential options to use with the MPlayer are -gui and –nogui. Just like the name suggests, if you want to play a file with GUI, you will include the -gui parameter. If not, use -nogui.

mplayer -gui music-file.mp3
or;
mplayer -nogui music-file.mp3

Those are but a few options you can use with the MPlayer utility. To view all of them, execute the command below:

mplayer --help

mplayer --help
MPlayer –help

Sox to play mp3 files in the command-line

Another powerful utility you can use to play mp3 files on your Terminal is Sox. Other than playing media files, Sox can convert various media file formats, record audio, and apply sound effects. This tool is available for most major distributions.

Install Sox on Ubuntu:

sudo apt update
sudo apt install sox
sudo apt install libsox-fmt-all

To play mp3 music with Sox, execute the command below:

play music-file.mp3

Sox
Sox

To play all the mp3 files in a directory, run the command below;

play *.mp3

Sox Playlist
Sox Playlist

Conclusion

Those are some of the best tools you can use to play mp3 files in the command-line. My favorite is VLC since it supports many media formats and comes with an intuitive Ncurses command-line interface. However, that shouldn’t limit your decision. Pick the tool that you feel comfortable with and enjoy your music.

Arun Kumar
Arun did his bachelor in computer engineering and loves enjoying his spare time writing for FOSS Linux. He uses Fedora as the daily driver and loves tinkering with interesting distros on VirtualBox. He works during the day and reads anything tech at night. Apart from blogging, he loves swimming and playing tennis.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,281FansLike
386FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

MUST READ

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

Top 20 must-have apps for your Ubuntu PC

OK, this one is going to be a long one, so grab a cup of coffee and scroll through the best apps that we think are must-have for your Ubuntu PC. We have hand-picked each one of these considering the most common categories that suit an average Linux user.

The 6 Best Linux File Recovery Software

Now and then, most of us lose important data in our computers either through accidental deletion, virus attacks, permanent removal of files, etc. Some of these files contain critical information that cannot be assumed and needs recovery. In this post, we will discuss some of the best data recovery available for Linux systems. The fantastic part is that most of them are opensource and freely available for use.

Linux Vs. Windows: 10 Key Differences to Know

Merely going by statistics, it is most likely that you are a Windows user.  After all, around  87.70% of all PCs around the world run on Windows with Linux, only accounting for 2.32%.

13 ways to use the copy command in Linux (with examples)

Being a Linux user, copying files and directories is one of the everyday tasks that you have to carry out. It can be copying a file to make a backup or copy it to another partition, directory, or external storage drive.