Lightweight, command Line music player for Linux

To start out, I used this idea. I wrapped this method up into an init script to get it working at startup and shutdown like this.

So, the first thing you’d need to do is install mplayer.

sudo apt-get install mplayer

Then, you’d need to have a simple init script to run when the machine starts up.

sudo nano /etc/init.d/auto_music_starter

and paste something like this in.

#! /bin/sh
# /etc/init.d/auto_music_player

# Some things that run always
touch /var/lock/auto_music_player

# Carry out specific functions when asked to by the system
case "$1" in
    echo "Starting Auto Music Player"
    cd /home/rubylaser/Music
    find . -name "*.mp3" -o -name "*.flac" -o -name "*.m4a" > playlist.txt
    mplayer -shuffle -playlist /home/rubylaser/Music/playlist.txt
    echo "Stopping Auto Music Player"
    mplayer_pid=`ps -C mplayer | tail -n1 | sed -e 's/^[ \t]*//' | cut -d " " -f1`
    kill -9 "$mplayer_pid"
    echo "Usage: /etc/init.d/auto_music_player {start|stop}"
    exit 1

exit 0

You’ll want to replace the /home/rubylaser with your username. Then set the script up to be executable.

sudo chmod +x /etc/init.d/auto_music_starter

Then, set it up to be run at startup and shutdown.

sudo update-rc.d auto_music_starter defaults 99

The 99 has it startup late in the boot process, otherwise my music ended up sounded like it was playing back at a slower rate than it should be. You can start and stop the player from the command line at any time too.

sudo /etc/init.d/auto_music_starter stop
sudo /etc/init.d/auto_music_starter start

I hope this can help you in some way.

Here is the post that I responded to.


I love learning new things and trying out the latest technology.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.