Command Line – How to Tell What Command Opens an Application

applicationcommand line

It happens every now and then that there's an application installed in my system which I don't know how to run from the command-line.

To find out, I usually Google or search the output of lsof (not always successfully) after running the application from the GUI.

There has to be an easier way. What is it?

Best Answer

Applications which you can start from your desktop environment are described by .desktop files, which are stored in /usr/share/applications and ~/.local/share/applications (strictly speaking, the corresponding XDG directories, but those are the default settings). Given an application name, as shown by your desktop environment, you can look for it in those files and find the corresponding Exec line.

To do this, you can use GUI menu editors such as GNOME’s Alacarte or MenuLibre, or search on the command line.

Alacarte (“Main Menu” in GNOME) shows all available applications, and the properties of each entry show the corresponding command:

Alacarte screenshot showing the launcher properties for “Users”

In a terminal window, this “Users” application can be found using

grep -l Name.\*=Users {/usr,~/.local}/share/applications/*.desktop |
xargs -r grep Exec=

This shows

Exec=gnome-control-center user-accounts

and true enough,

gnome-control-center user-accounts

on the command line opens the corresponding panel.

For DB Browser, you’d run

grep -l "Name.*=DB Browser" {/usr,~/.local}/share/applications/*.desktop |
xargs -r grep Exec=

In some cases the Exec line will have additional arguments, e.g. %f; those are placeholders for arguments such as files.

Related Question