Change default applications on Linux from terminal
post, Jan 14, 2026, on Mitja Felicijan's blog
Changing default applications is done with command xdg-mime. This is a
command line tool for querying information about file type handling and adding
descriptions for new file types. Make sure you have this program installed.
Application will use .desktop files to associate applications with specific
types.
Location and structure of .desktop files
ls /usr/share/applications
ls ~/.local/share/applications
You can add your own .desktop files to ~/.local/share/applications.
An example of .desktop file for Brave browser located in
~/.local/share/applications/brave.desktop.
[Desktop Entry]
Exec=/home/m/Applications/brave
Type=Application
Categories=Applications
Name=Brave Browser
Query current associations
You can query specific types with xdg-mime.
xdg-mime query default text/plain
xdg-mime query default text/html
xdg-mime query default x-scheme-handler/http
xdg-mime query default x-scheme-handler/https
xdg-mime query default inode/directory
Or you can look at the files containing this data.
less ~/.config/mimeapps.list
less /usr/share/applications/mimeapps.list
Set default application
# Set Brave as default browser.
xdg-mime default brave.desktop x-scheme-handler/http
xdg-mime default brave.desktop x-scheme-handler/https
# Set Thunar as default file explorer.
xdg-mime default thunar.desktop inode/directory
# Set Mousepad as default txt editor.
xdg-mime default mousepad.desktop text/plain
Interfacing with C
This simple example lists all registered types. But you can see where this can
go. This could be turned into ncurses CLI application that is used for setting
and changing default applications.
#include <gio/gio.h>
int main(void) {
GList *types = g_content_types_get_registered();
for (GList *l=types; l!=NULL; l=l->next) {
g_print("%s\n", (char *)l->data);
}
g_list_free_full(types, g_free);
return 0;
}
Compile with clang -o main main.c $(pkg-config --cflags --libs gio-2.0).
Reading material