I often find that I need to figure out the command to execute a certain application, such as an Alarm Clock application or the System Monitor. However, many of the actual CLI commands to run these are not directly evident. What I usually do is just go to the Ubuntu Software Center, then search for the application's "common name" and hence find its package/command name. I would like to know if there is an easier or more efficient way of doing this.

I was wondering if there is a command similar to xprop, where clicking on an open (graphical) application would output its command in the terminal. In other words, I am interested in a graphical way of finding an application's command.

For example, if I run such a command and click on System Monitor, the terminal would output gnome-system-monitor, etc. Thanks.

PS. If a solution is not currently available, I would be interested in writing my own script with this functionality. I only know basic bash, however. I realize that should probably go under a separate question, but I'm just throwing it out there.

  • Possible dupe: askubuntu.com/questions/23272/… – Kevin Bowen Mar 8 '13 at 5:03
  • @maggotbrain Though this does answer my question, a graphical method would be optimal. But thanks! – deox Mar 8 '13 at 5:20
  • I thought as much. I held off on flagging it for closure. In that case, can you edit and clarify your question? – Kevin Bowen Mar 8 '13 at 5:25

I know you prefer a graphical route but here's my effort as a learner of CLI stuff ...

To list names with commands:

grep '^Name=' /usr/share/applications/*.desktop > ~/Desktop/mgtl1.txt && grep -h '^Exec=' /usr/share/applications/*.desktop > ~/Desktop/mgtl2.txt && paste -d':' ~/Desktop/mgtl1.txt ~/Desktop/mgtl2.txt > ~/Desktop/mgtl3.txt && perl -p -i -e 's/\/usr\/share\/applications\///'g ~/Desktop/mgtl3.txt && perl -p -i.bak -e 's/\n/\n\n/'g mgtl3.txt && perl -p -i.bak -e 's/:/\n/'g mgtl3.txt  

will create four files on the desktop and mgtl3.txt will look like this in part:

Name=Report a problem...  
Exec=/usr/share/apport/apport-gtk -c %f

Exec=audacity %F

Name=Bluetooth Manager  

To find the command for any software
Launch the software. Then, run

COLUMNS=150 ps -ef > ~/Desktop/out.txt  

Examine the last few lines of out.txt for the relevant command.

| improve this answer | |
  • A little complicated, but otherwise good answer. +1 – Seth Mar 8 '13 at 16:00
  • It got complicated because not all .desktop files have Name= first and Exec= second. Those made it difficult for me. – user25656 Mar 8 '13 at 16:11
  • @Seth, see this post: ubuntuforums.org/… I asked someone to post a .desktop file that comes with the Ubuntu version of LibO. If you look at it, you'll see that the Exec= line comes first, unlike the order in many other .desktop files which have Name= first. Actually, the order is Exec, Name, Name Exec! Bit bizarre. And that's what I see in my version of LibO as well ( direct from libreoffice.org). – user25656 Mar 8 '13 at 16:25

using UNITY

Dash -> Search for Terminal

Dash -> More Apps -> 'See More Results'

Dash -> More Apps -> Accessories

using Terminal Keyboard Shortcut: Ctrl + Alt + T

read this http://www.ee.surrey.ac.uk/Teaching/Unix/unix1.html

| improve this answer | |

I wrote this (rather ugly) script to find the command to execute a running application by clicking on it. It uses xprop to get the "clicking interface" and to get information about the selected window:


xprop > ./tmp

chk_desk=`grep -c "_NET_WM_DESKTOP_FILE(STRING)" ./tmp` #Checks whether application has a corresponding .desktop file. The '-c' counts the number of matches.

if [ $chk_desk -ne 0 ] ; then
    desk_line=`grep "_NET_WM_DESKTOP_FILE(STRING)" ./tmp` #Extract line containing .desktop path 
    desk_path=${desk_line/"_NET_WM_DESKTOP_FILE(STRING) = "/} #Extract only the .desktop path
    desk_path=${desk_path//\"/} #Removes quotes
    exe_line=`grep "Exec=" $desk_path | head -n1`
else #If .desktop doesn't exist, it uses the PID to find the executable
    pid_line=`grep "_NET_WM_PID(CARDINAL)" ./tmp` 
    pid=${pid_line/"_NET_WM_PID(CARDINAL) = "/}
    exe_path=`readlink -f /proc/$pid/exe`

echo $exe

rm ./tmp

exit 0

In case you are wondering, I could not have used only the PID for matching since /proc/$pid/exe gives you the path of the "real" executable, or of the underlying service running the program. So if you used it on say 'geogebra', the script would output java instead. Or in the case of Firefox you would get the path /usr/lib/firefox/firefox, which I suppose is where the actual firefox executable exists, which means the /usr/bin/firefox points to it.

While firefox is not a big problem (you could use the "real" executable), for the java based applications the .desktop file is needed to get the command to run the actual application and not a blank java session.

This script, of course, will only work if you are using X as your display server (since it uses xprop). I'm sure there must be a way to make the script cleaner, though my main problem was having to create many variables to hold the grep line outputs and the multiple substitutions.

| improve this answer | |
  • Thanks to all of you for helping! And I would certainly appreciate other methods of accomplishing this, or ways of improving the script. Thanks. – deox Mar 10 '13 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.