6

I can click the "movie player" from the GUI of Ubuntu, but how could I know the corresponding command line cmd. I want to run the movie player from commmand line.

And this is not only about the background command for the movie player, I want to know all the actual command that was run by the x-window shell when I click on one of the icon on the menu.

Many thanks.

2
  • You say "GUI of Ubuntu", but are you taking about Gnome (the default GUI for Ubuntu), or KDE (For Kbuntu) or XFCE (For xubuntu). The answer is different for each GUI. Jun 2, 2010 at 21:37
  • @stefan: let's assume, based on the tags, that the user is looking for solutions based on Xubuntu/XFCE. (yes, those tags were added by someone else, but that was based on a comment on one of the answers below.) Jun 3, 2010 at 4:26

10 Answers 10

6
+100

open the console and enter

ps --sort start_time x

this should give you a list of active processes, sorted by starting time, with the most recent process at the bottom. For example, I've just started Firefox and got this:

19713 ?        S      0:00 /bin/sh /usr/lib/firefox-3.6.3/firefox
19718 ?        S      0:00 /bin/sh /usr/lib/firefox-3.6.3/run-mozilla.sh /usr/lib/firefox-3.6.3/firefox-bin
19722 ?        Sl     0:01 /usr/lib/firefox-3.6.3/firefox-bin
19737 pts/2    R+     0:00 ps --sort start_time x

Of course ps --sort start_time x is always the most recent process.

3
  • IIRC processes can change this description in runtime. Jun 2, 2010 at 21:28
  • To only show the 10 most recently executed processes, -start_time and head could be used: ps --sort -start_time x | head Jun 2, 2010 at 21:30
  • @Maciej That's true, but most processes do not. Jun 2, 2010 at 21:30
4

Right click on the icon and select Properties. That will tell you the command line associated with it in most cases.

4
  • This works for Gnome (the standard desktop manager for Ubuntu), but it doesn't work for all desktop managers.
    – stib
    May 21, 2010 at 8:09
  • I am using Xubuntu, and right click run the program. May 21, 2010 at 16:03
  • 1
    even in Gnome, this only works for program launchers on the panel or on the desktop. it doesn't work within the menu. Jun 2, 2010 at 16:27
  • 3
    For menu (in Gnome), there's a menu editor to peek at the commands run at a click. Just right-click and select 'Edit menu', then navigate to the item and check its command-line.
    – chronos
    Jun 2, 2010 at 18:12
3

The three main GUIs for Ubuntu are Gnome, KDE, Xfce. These projects all try to follow the Free Desktop standards at freedesktop.org . Xfce appears to follow the Desktop Entry standard, which defines how menu items are handled, among other things.

The following instructions should work in Gnome, KDE and Xfce.

The menu items (Also called 'Launchers', or 'Desktop Entries' are stored in /usr/share/applications.

You know this application is called "Movie Player", so to find the appropriate file do this:

stefanl@HOST:/usr/share/applications $ grep -i "movie player" *.desktop
totem.desktop:Name=Movie Player

Grep shows me that 'totem.desktop' contains the appropriate content. From this, I know that "Movie Player" is associated with the 'totem' application.

Now, to see the command which is executed by this menu item, you search for Exec:

stefanl@HOST:/usr/share/applications $ grep Exec totem.desktop 
Exec=totem %U

The format of these Gnome/KDE/Xfce .desktop files is further described at the freedesktop.org Desktop Entry Specification. The Desktop Entry Specification: The Exec key describes the use of the %U key:

A list of URLs. Each URL is passed as a separate argument to the executable program. Local files may either be passed as file: URLs or as file path.

1
  • 1
    you can also examine the launchers in the menu with alacarte (aka System -> Preferences -> Main Menu); find the menu entry in Alacarte, and look at the properties to see the commandline being run. i'm pretty sure launchers are installed to the same place in Xubuntu, but i don't know if Alacarte is included. Jun 3, 2010 at 4:27
1

If you want a movie player you can control from command line as well, use mplayer.

1

Note: This answer is an extension of artistoex's answer.

This command should display all currently running commands executed by the current user and started within the last 60 seconds:

ps x --sort -start_time -U YOURUSERNAME -o start,command | \
awk '$1>=recently&&$1<=now' \
recently=$(date --date='60 seconds ago' +%T) now=$(date +%T) | sed 1,1d

To use this command, click on an icon or menu item to execute a command and while the program that was just opened is still running, execute the above command. Remember to replace YOURUSERNAME with the username of your current user.

Explanation:

ps will display currently running processes. Explanation of ps arguments:

  • x: includes processes not executed through a terminal (actually a tty). Adding -t '?' would display only processes not associated with a terminal.
  • --sort -start_time: sort the output by the time the process started (descending order)
  • -U YOURUSERNAME: Replacing YOURUSERNAME with your username will show only processes executed by your user. This restriction can be removed if needed.
  • -o start,command: Display two columns in the output: the start time of the process and the command that was executed

awk is used here to only show processes executed recently. Explanation of awk arguments:

  • $1>=recently&&$1<=now: Restrict the output to processes that were executed within the last 60 seconds. To change this time frame, modify the next argument (recently variable assignment)
  • recently=$(date --date='60 seconds ago' +%T): set the awk variable recently used in the previous argument to 60 seconds ago in HH:MM:SS format (ps time format).
  • now=$(date +%T): set the awk variable now to the current time (this is to exclude processes executed less than 24 hours ago that would look like they executed in the future)

I added sed 1,1d to delete the first line of output because it will show the currently executing command, which is pointless to display.

Keep in mind: Using ps to find out which process was executed will not work as expected for certain programs. For example, if you click on a Firefox shortcut but Firefox is already running, a new process will not be created and the start time of the old process will not be changed. However, this method does work fairly well for many programs.

1

In Xubuntu, go to user/share/applications and right click on any apps you want to put in a panel. Select send (link) to Desktop. Now the launchers are on the desktop, you can right click any one and select Properties to see the command line. Right click in a panel, select create a launcher, and duplicate the properties in desktop launcher for each app. Now you can delete the launchers on the desktop.

It's a little more roundabout than in Ubuntu (Gnome), but Xubuntu is faster because it trims out all the goodies.

0

That would be totem.

0

What appears on the menu is controlled by the files in .desktop files in /usr/share/applications. If you view any of these files there is a line Exec= something, this is the command that Ubuntu runs when you click the icon.

0

This answer is an extension of Cry Havok's.

I think this is the easiest way.

First you need to get whatever shortcut you have in the application launcher copied to your desktop. You can right click any application and select "Add this launcher to Desktop" (if you are using gnome).

Now that the shortcut is on the desktop, you can right click it and select properties. There in the Basic tab it will show you the command line command that was initiated to launch the application.

You can also open up gedit and open up the desktop Icon. Desktop icons are just text files with a ".desktop" extension. In this file you will see all of the parameters of that shortcut including the "Exec=" part that shows the program that can be called from the command line.

0

If you're using gnome, its

 gnome-open <file> 

gnome-open then opens the file using the program that has been registered to open that file. However, if you wan't to know the final process thats running, you can try

ps ux | grep filename

or you could search from the output of

ps ux

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .