Quick Links

Need a way to play your collection of MP3, OGG, and FLAC music files right from the Linux command line? Here's how to do it with a competent, lightweight terminal-based player.

Music on Console

Even in these days of cloud-based streaming music platforms like Amazon Music and Spotify, the chances are you'll still want to play something from your local collection of audio files from time to time. Perhaps you have something so obscure the streaming services don't have it. Or you ask for a particular track and they keep playing you the live version, or the extended remix, or any of the other variations when all you really want is the plain old as-first-released album track.

Related: How to Put Your Music Collection Online and Access It From Any Device

Of course, Linux is well served with music players. RhythmboxClementine, and Strawberry are fully-featured, sophisticated, and polished applications for managing your music collections. As well as playing your music they'll do things like search for and download missing album art, play podcasts and internet radio, and edit the meta-data in the files themselves.

But what if you want to access your music collection from a terminal window, without the overhead of a fully-loaded music player? Music on Console, or MOC, is a program that allows you to do just that. It loads in the blink of an eye, lets you search your music collection, find what you want to play, and just play it.

It supports multiple sound file formats, playlists, and even basic themes. If you're a keyboard junkie and tend to hang around in terminal windows, MOC is a natural fit for you. It is fully keyboard-controlled. Once the keybindings burn themselves into your muscle memory you can control MOC without having to take your hands off your keyboard.

When you have a long-running process in a terminal window there's always the chance that you close the terminal window by accident. But even if you do, MOC's got a neat trick to deal with that too.

Related: What Are the Differences Between MP3, FLAC, and Other Audio Formats?

Installing MOC

Installing MOC on Ubuntu is straightforward:

sudo apt install moc

Command to install moc on ubuntu

To install MOC on Manjaro is just as easy:

sudo pacman -Sy moc

Command to install moc on Manjaro

To install MOC on Fedora takes a few extra steps.

First, we use wget to download the details of the RPM Fusion repository. We were using Fedora 34. If you're using a different version such as 35, substitute the version you're using for the "34" in the command.

wget http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-34.noarch.rpm

Downloading repository details on Fedora

Then we install the details of that repository.

rpm -Uvh rpmfusion-free-release-34.noarch.rpm

Installing repository details on Fedora

With that done, we can go ahead and install MOC:

sudo dnf install moc

Installing MOC on Fedora

The MOC Config File

On Ubuntu and Manjaro, MOC started straight away. On Fedora, we had to edit the MOC configuration file first. It's a good idea to edit the MOC configuration file anyway, to add the location of your music directory. The configuration file is called "config" and is located in the ".moc" directory in your home directory.

Open a terminal window and make sure you're in your home directory. Open the configuration file in an editor. We used gedit:

gedit .moc/config

Find and edit, or add these two lines. Replace "dave" in these lines with the name of your own user account:

mocdir = /home/dave/.moc 
    

MusicDir = "/home/dave/Music"

On Fedora, we also had to add this line:

TiMidity_Config = /etc/timidity.cfg

Editing the MOC configuration file

TiMidity is a MIDI library used by MOC.

For security reasons, we need to make sure the configuration file is only writable by the owner. We'll use the chmod command with the read-write/read/read mask of 644.

chmod 644 .moc/config

Seting access privileges on the MOC configuration file with chmod

Now we're ready to start MOC.

First Steps with MOC

The command to start MOC is mocp. Note the added "p" that stands for "player."

mocp

Starting MOC with the mocp command

The default view has a directory listing on the left and a playlist on the right. If you've configured your music directory in your ".moc/config" configuration file, MOC will open with your music directory displayed in the left-hand pane.

The MOC default layout

If you navigate away from your music directory, you can quickly return to it by pressing the "m" key.

You can move the highlight bar with the "Up" and "Down" arrow keys, and the "Home", "End", "PgUp" and "PgDn" keys. Hitting "Enter" will select the highlighted item.

  • If a directory is highlighted, you'll enter that directory.
  • If the highlight is on the "../" symbol you'll go up one directory in the directory tree.
  • If you're highlighting a music file, MOC will play that music file.

The "Space Bar" or the "p" key pauses and unpauses playback. The keybindings in MOC are case-sensitive, so make sure you use a lowercase "p." The "s" key stops playback.

MOC playing a music track

Pressing the "," and "." keys decreases or increases the volume by 5%. For fine control, "<" and ">" adjust the volume in steps of 1%. Pressing "Alt" with a number key from 1 to 9 sets the volume to 10%, 20% up to 90%.

Closing MOC

Uppercase "Q" closes MOC and stops playback. Pressing lowercase "q" closes the MOC client but leaves the back end running.

That means you can close the MOC client---and the terminal window---and MOC will continue to play music in the background. Opening a new terminal window and using the mocp command starts a new client that automatically connects to the background process, letting you regain control of it.

Using Playlists

Pressing "a" with a music file or directory highlighted adds them to the playlist. Handily, the highlight is moved to the item below the one you just added.

Pressing "d" with a playlist item highlighted removes that item from the playlist. Once you have some items in the playlist pane you can move between the directory and playlist panes using the "Tab" key.

Populating the playlist in MOC

Pressing the "l" key (lowercase "L" for "layout") toggles between the default "dual pane" view and a single pane view.

In the single pane view, the "Tab" key still swaps between the directory listing and playlist views, but with one "maximized" single pane.

MOC single pane view of a directory

Useful Keybindings

Playing about with MOC for ten minutes will give you most of what you need to know. You can get help by pressing "h" or "?", but here's a quick list of the most important keys.

Closing MOC

  • q: Close the client, leave MOC running in the background.
  • Q: Close the client and the background process.

Playing Music

  • Enter: Play a track.
  • Space or p: Pause playback.
  • n: Next track.
  • b: Previous track.
  • s: Stop playback.
  • ,: Reduce volume by 5%.
  • .: Increase volume by 5%.
  • <: Reduce volume by 1%.
  • >: Increase volume by 1%.

Using Playlists

  • a: Add a track to the playlist. Also works with directories.
  • A: Add a directory to the playlist.
  • d: Delete an item from the playlist.
  • C: Clear the playlist.
  • u: Move a track up in the playlist.
  • j: Move a track down in the playlist.

Miscellaneous

  • Tab: Move between the directory and playlist panes
  • l: Switch between two-pane and single-pane layouts.
  • /: Search directory and track names.

Coda

Music on Console is refreshingly straightforward and satisfyingly competent. It gives you all the basic functions of a music player, accessible from the keyboard.

That's music to a terminal jockey's ears.

Related: Become a Linux Terminal Power User With These 8 Tricks