Managing My Music Files with the Command Line

I recently wrote an article for, “Why I switched from Apple Music to Jellyfin and Raspberry Pi.” I hope you’ll read that first — or at least skim it — because it’s really fun and you’ll have more context for this post.

When managing my digital music collection during the move to Jellyfin, I noticed quite a large number of files that were either missing or messed up. iTunes had placed albums in odd places, or named them strange things using odd characters. Managing all of this using a graphic interface is pretty easy. You just drag folders or songs where you want them. You can also just click on a file and rename it.

However, it’s not as simple with my new setup. I’m running the Raspberry Pi using Ubuntu 20.0.4 LTS. That means there’s no GUI. Even if I hooked up a monitor, it would still be the terminal window. So I log in to the server from my laptop via ssh. Then I’m working directly in my user account. When I log in, it looks like this:

screenshot of pi login terminal window

Then, to move into my music folder on the server, I use the command cd /mnt/music. That gets me a very long list of artists:

Terminal window showing list of directories

If I want to look into a certain album, I have to change directories again to first view that artist, then the album. For example, if I want to see Elton John’s Greatest Hits, I use the command cd 'Elton John', then list all the albums I have for him with the command ls. Then I move into the album with cd 'Greatest Hits'. If I knew which directory I wanted from the start, I could just type it all at once like: cd 'Elton John'/'Greatest Hits'. Since I didn’t know, I had to look first.

Terminal window showing list of Elton John album directory and files

You might imagine that this can get tedious after a while, especially if you don’t know what you’re looking for. Yes and no. Sometimes it’s nice to stay on the keyboard and save myself from moving to the mouse all the time. Sometimes it’s frustrating when I make too many typos. But it is the only way to work in a server with no fancy GUI.

Fixing the music

In the Greatest Hits song list, I noticed that there are two versions of Crocodile Rock. It’s a great song, but I only need one copy. Since all the other files are .m4a and the second version is an .mp3, I made the executive decision to delete the latter file. So I run the command rm 'Crocodile Rock.mp3' and it’s gone forever.

Since my whole family shares our music collection, I’ve asked them to tell me when something doesn’t play or is missing. They only access the music through Jellyfin, so once they sound the alarm — and sometimes it sure seems like an emergency — it’s up to me to fix it on the server.

For example, for some reason Apple took songs that I had imported from my own CDs and converted them to .m4p files. That means they’re protected and can’t be played anywhere but in Apple Music (formerly known as iTunes). That was the impetus for me to switch to an open source media player in the first place. But I still had to fix those files. The only way to do it was to rip the CDs again and import them again.

It was a lot of drudgery, but I learned a lot in the process.

Writing bash scripts to make it easier

After I got used to maneuvering around the Ubuntu server via the command line, I decided it would be nice if I could make things a little faster and easier. I wrote a couple of simple scripts to do that, and in my next post I’ll share them with you.


Did you enjoy this post? Subscribe privately in your favorite RSS reader!

Right-click the icon to copy the link to my feed.

RSS logo

Or, sign up below to get updates and exclusive content sent to your inbox:

Oh hi there 👋 It’s nice to meet you.

Sign up to receive new content in your inbox, at least every month. Maybe a couple of times.

I don’t spam! I’m vegan.




Leave a Reply

Your email address will not be published. Required fields are marked *