Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I get list of installed apps (based at files in /usr/share/applications/) without writing own parser? I need just app name, path to app icon and path to launch app.

I'm using C++ with Qt libraries. Of course, you can write me shell command or something else like it.

share|improve this question
What do you mean by application? Which distribution? – Matteo Jun 15 '12 at 14:25
@Matteo by 'application' i mean everything that is displayed in dash, Start menu or smth like this. – Ivan Akulov Jun 17 '12 at 7:32
The parser it not hard to write, all entries use the "A[LANG]=B" form, you only need to combine QDir and QFile and little regex – warl0ck Sep 7 '12 at 5:53
@warl0ck Already wrote :) – Ivan Akulov Sep 7 '12 at 12:47
up vote 1 down vote accepted

Here's a quick-and-dirty shell script that might help you. Adjust the output format to something that's easy to parse for you. Finding the right icon could use some improvement to select the highest resolution image. Maybe there's a better way to get the optimal icon using gconftool or something, I don't know.



error() {
    echo $*
    exit 1

is_icon() {
    test -f "$1" && icon_path="$1" && return 0
    icon_path=$(find $2 -name $1.png | sort -r | head -n 1)
    test -f "$icon_path" && return 0

find_icon() {
    test "$icon_filename" || return
    is_icon $icon_filename $icon_basedir1 && return
    is_icon $icon_filename $icon_basedir2 && return
    is_icon $icon_filename $icon_basedir3 && return
    is_icon $icon_filename $icon_basedir4 && return

find_name() {
    test "$fullname" && name=$fullname && return 0
    test "$genericname" && name=$genericname && return 0

find /usr/share/applications -type f -name \*.desktop | while read file; do
    icon_filename=$(cat $file | grep ^Icon= | sed -ne 's/^.*=//' -e '1 p')
    executable_name=$(cat $file | grep ^Exec= | sed -ne 's/^.*=//' -e 's/ .*//' -e '1 p')
    fullname=$(cat $file | grep FullName.en_ | sed -ne 's/^.*=//' -e '1 p')
    genericname=$(cat $file | grep GenericName.en_ | sed -ne 's/^.*=//' -e '1 p')
    name=$(cat $file | grep -i Name | sed -ne 's/^.*=//' -e '1 p')
    echo app_file=$file
    echo name=$name
    echo executable=$(which $executable_name || echo $executable_name)
    echo icon=$icon_path
share|improve this answer

As far as I remember /usr/share/applications/ is Gnome windows manager specific and does not contain an entry for every application on your system (BTW you should define what do you mean by application).

In any case you can just list the entries in the directory

share|improve this answer
He did define what an application is for him, a program that has an entry in /usr/share/applications. – Marco Jun 15 '12 at 14:58
Wouldn't that be ls? – jippie Jun 15 '12 at 17:44
Exactly, hence my comment. It seems strange that he is just asking how to list the files in a directory. – Matteo Jun 16 '12 at 7:13
@jipple, not file list in directory, but App name (like Chrome), path to icon and path to running file (like /opt/google/chrome/google-chrome). It's written in .desktop files in /usr/share/applications/ directory. – Ivan Akulov Jun 17 '12 at 7:30
Are you sure that it's Gnome-specific? E.g. I have kde4 subdirectory in /usr/share/applications/ with .desktop files for kde apps. – Ivan Akulov Jun 17 '12 at 7:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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