If you are addicted to the Terminal and always find the ways to do every possible thing inside the Terminal, then why not listening to music through it. The command line or Terminal gives you everything you need in a more efficient and faster way while also utilizing fewer resources. It also becomes handier when you are using a headless version of your operating system.
In this article, we are going to look at some tools using which you can listen to your favorite music right from your command line. This may be useful in scenarios such as the one I described above. Moreover, we will explain how to install and use these tools and also to remove them if needed.
We have run the commands and procedures mentioned in this article on a Debian 10 OS.
Method 1: Using MOC
MOC or Music on Console is a Terminal based music player for Linux and UNIX operating systems. It is an easy yet powerful tool. All you need to do is to simply install the player, select the directory and start playing. MOC supports several audio file formats including mp3, OGG, Wave, SID, AAC, MIDI, Speex, WMA, DTS, and some others.
Launch the Terminal application in your Debian OS. For that, go to the Activities tab in the top left corner of the desktop. Then in the search bar, type terminal. When the Terminal icon appears, click on it to launch it.
Execute the following command in Terminal to revive the list of available packages:
$ apt-get update
Then, we will need to install the MOC and MOC FFMPEG plugin that will help the moc player in recognizing many other audio formats. Execute the following command to do so:
$ apt-get install moc moc-ffmpeg-plugin
When the system prompt with a y/n option to continue the installation, enter Y to continue. It will take a while depending on your internet speed after that the software will be installed on your system.
In case you want to remove MOC player that was installed through this method, you can execute the following command in the Terminal:
$ apt-get remove moc moc-ffmpeg-plugin
Play music through MOC
Once installed, you can launch the MOC player from the Terminal using the following command:
You can then use the following keyboard shortcuts to control the music as you like:
- P-for playing music
- B-for playing the previous track
- N- for playing next track
- Q-for hiding the MOC interface
- H-for help on using the player.
Method 2: Using mpg123
mpg123 is an open-source audio player that allows you to listen to music via command line. It supports MPEG audio formats, including MP3. It is only a console-based application with no graphical user interface.
The mpg123 utility is available in the package repository of Debian OS and we can easily install it through the command line using the apt-get command. Execute the following command in terminal to do so:
$ apt-get install mpg123
When the system prompts with a y/n option to continue the installation, enter Y to continue. It will take a while depending on your internet speed after that the mpg123 player will be installed on your system.
To play the music, just navigate to the directory containing the music files and simply type mpg123 followed by the file name. Alternatively, if you do not want to navigate to any directory, just type mpg123 followed by the path to music file.
$ mpg123 <path/to/file>
If you ever want to remove mpg123 installed through this method, you can use the following command in the Terminal:
$ apt-get remove mpg123
Method#3 Using Sox
Sox is a very simple Terminal-based utility that converts various audio file formats into other formats. We can also play music through it. Sox is supported on all major platforms like Windows, Linux and macOS. It is available in official repositories of Debian OS. We can install it using the apt-get command. Execute the below command to do so:
$ apt-get install sox
Then execute the below command in Terminal to install the necessary codecs:
$ apt-get install sox libsox-ft-all
When the system prompts with a y/n option to continue the installation, enter Y to continue. Wait for a while until all the required packages are installed.
To play music using sox, navigate to the directory where the music files are placed, and simply type play followed by music file name along with format.
$ play file_name
That is all there is to it! I hop it will be helpful whenever you need to listen to music through your Terminal.