For more useful commands, see the Cmus cheat sheet.
This article explains how to update the Cmus music library so that Cmus reloads and updates the database with newly added music.
To update (reload/refresh) the Cmus music library, use the following commands:
The following Cmus command scans the specified directory and adds its music files to the library.
:add /path/to/your/music
The following Cmus command rescans the existing music library for changes, updating file metadata and detecting new or modified tracks.
:update-cache
To remove missing files, run the following two Cmus commands.
:clear
:add /path/to/your/music
Breakdown:
:clear
removes all tracks from the current library or playlist without deleting any files from the disk.:add
scans the specified directory and adds its music files to the library.There are two ways to update the Cmus library automatically. One is via a config file and the other is using a shell script. Neither option is particularly elegant, but it works.
To regenerate the Cmus library every time you start Cmus - which is equivalent to an update/refresh/reload - you can simply add the following command sequence to the Cmus config file (~/.config/cmus/rc
).
clear
add ~/Music/
add /path/to/your/music
update-cache -f
Breakdown:
clear
:add ~/Music/
:~/Music/
) and adds all supported audio files to the Cmus library. Adjust path or add paths needed, e.g. /path/to/your/music
.update-cache -f
:This sequence clears the library, adds files from the specified directory, and forces a metadata refresh.
If you do not want to regenerate the Cmus library every time you start Cmus, but still want to rebuild the database with a key, you can simply call a script with a key in Cmus. Just do the following:
Create a Bash script
#!/bin/bash
# Remove all tracks from Cmus library without deleting any
# files from the disk.
cmus-remote -C clear
# Scans the specified directories and adds contained music
# files to the Cmus library.
cmus-remote -C "add ~/Music"
cmus-remote -C "add /path/to/your/music"
# Forces a full rescan of the entire library, refreshing
# metadata and checking for changes in the files.
cmus-remote -C "update-cache -f"
In my case, I called the file update-cmus-library.sh
and I’ve placed it in my ~/Bin
directory.
Make the script executable
chmod +x ~/Bin/update-cmus-library.sh
Learn more about permissions in Linux.
Bind the update script to u
key in Cmus
:bind -f common u shell ~/Bin/update-cmus-library.sh
In Cmus, just use shift
+Ctrl
+v
to pase this command. Press Enter and your are done. You can immediately use the u
key to update the library.
In Cmus, go to Settings View to check if the binding worked. It should be listed under Keybindings like that: common u shell ~/Bin/update-cmus-library.sh
.
Sources and recommended, further resources on the topic:
License: How to update the Cmus music library by Jonas Jared Jacek is licensed under CC BY-SA 4.0.
This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/instructions/how-to-update-cmus-library">How to update the Cmus music library</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>
For more information see the DITig legal page.