28

I know, I just can hit Super+A to see all installed apps in Ubuntu, but I need a command to list their names. The command

dpkg --get-selections | awk '{print $1}'

is also not an option because it shows all installed packages and it contains drivers, kernels and libraries.

Danatela
  • 13,414

6 Answers6

22

I came up with this answer for people who wants to use bash in a good way. It's clear that the answer of the question is related to the listing of the files from /usr/share/applications, but the problem is that ls command shouldn't be parsed ever. In the past, I was doing the same mistake, but now I learned that the best way is to use a for loop to iterate over the files, even if I must use some more keys from my precious keyboard:

for app in /usr/share/applications/*.desktop; do echo "${app:24:-8}"; done

I also used in the previous command string manipulation operations: removed from app first 24 characters which are /usr/share/applications/ and last 8 characters which are .desktop.


Update:

Another place where you can find applications shown by the Dash is ~/.local/share/applications/*.desktop. So you need to run the following command as well:

for app in ~/.local/share/applications/*.desktop; do echo "${app:37:-8}"; done

To unify the previous two commands, you can use:

for app in /usr/share/applications/*.desktop ~/.local/share/applications/*.desktop; do app="${app##/*/}"; echo "${app::-8}"; done
Radu Rădeanu
  • 174,437
10

To get the list of all your installed applications with their names, the easiest way is to do:

sudo apt-get install aptitude
aptitude -F' * %p -> %d ' --no-gui --disable-columns search '?and(~i,!?section(libs), !?section(kernel), !?section(devel))'

It will get you a nice list of all installed packages that are not libraries, not kernels, not development package like this:

* zip -> Archiver for .zip files 
* zlib1g -> compression library - runtime 
* zlib1g-dev -> compression library - development 
* zsh -> shell with lots of features 
* zsh-common -> architecture independent files for Zsh 

It's more complete since it also lists non-GUI applications that won't appear in the .desktop files

Braiam
  • 69,302
  • I can not agree with this answer to this question. The answer is nice, but not in this place. Is clear enough that the OP wants a list with applications which can be found in the Dash. And there is not place for zsh, zsh-common and others! – Radu Rădeanu Mar 16 '14 at 14:16
  • @RaduRădeanu I just used tail to show an excerpt of my installed packages, which ends with z, if I had used head, they will start with a, 2) he wants applications listed in the "dash"? Are you sure? – Braiam Mar 16 '14 at 14:17
  • Braiam, came on, it is not about which start with z or with a... When you hit Super+A on your keyboard what can you see appearing on your screen starting from the top-left corner? – Radu Rădeanu Mar 16 '14 at 14:29
  • @RaduRădeanu frequent applications since I use GNOME3. – Braiam Mar 16 '14 at 14:55
  • Very nice - GNOME3. But the the OP sees installed apps, not frequent apps, so ho doesn't using GNOME3 and I suppose that he use the default Unity. If you have doubts, you can ask him in one comment. – Radu Rădeanu Mar 16 '14 at 15:04
  • @RaduRădeanu you are assuming too many things about OP. He wants to see all the installed applications, mine list them all. – Braiam Mar 16 '14 at 17:13
  • 1
    @RaduRădeanu OP's title says that he wants to list all applications installed in his system excluding libraries, drivers, kernels and others.. He mentions one of the way (which he uses) to get the app-list, which is using Super + A and that just displays a subset of the applications installed in the system; but this covers most if not all.. the answer would be even complete with --no-gui removed. – rusty Mar 16 '14 at 17:16
  • 1
    ..I take back the --no-gui part, seems it's not there for what I thought it was. – rusty Mar 16 '14 at 17:28
2

Run the below command to see all the installed applications,

ls /usr/share/applications | awk -F '.desktop' ' { print $1}' -

If you want to get the list of all installed applications, then run the below command,

ls /usr/share/applications | awk -F '.desktop' ' { print $1}' - > ~/Desktop/applications.txt

It will stores the above command output to applications.txt file inside your ~/Desktop directory.

OR

Also run the below command on terminal to list the installed applications,

find /usr/share/applications -maxdepth 1 -type f -exec basename {} .desktop \; | sort

To get the list in text file, run the below command

find /usr/share/applications -maxdepth 1 -type f -exec basename {} .desktop \; | sort > ~/Desktop/applications.txt

Desktop entries for all the installed applications are stored inside /usr/share/applications directory, where file names are in the format of application-name.desktop.Removing the .desktop part from the file names will give you the total list of installed applications.

Update:

As @Radu suggested, you can also find desktop entries for your additional installed applications inside ~/.local/share/applications directory.

find /usr/share/applications ~/.local/share/applications -maxdepth 1 -type f -exec basename {} .desktop \;
Avinash Raj
  • 80,616
  • 5
  • Thanks Radu however how many times have you seen a filename containing a newline? Never? Thought so . So I should never ever use something very useful because of an edge case that virtually never happens? I think I'll keep parsing ls - for representational purposes and for non-critical tasks such as the one above - and try to keep in mind this limitation, thank you for the heads up! – Rolf May 13 '18 at 14:43
1

Not sure why most of the answers posted involves extracting the filename of .desktop shortcuts. Your .desktop shortcut filename can be anything but what matters is the Name field inside the shortcut file. If you want to build the list of installed application names showing in Dash, just "grep" that field under [Desktop Entry]

Rudimental code, with bash

#!/bin/bash

for file in /usr/share/applications/*.desktop;
do
    while IFS== read -r key val
    do
        if [[ -z $key ]]; then
            continue
        else
            if [[ $key =~ ^\[Desktop\ Entry ]]; then
                interesting_field=1
            elif [[ $key =~ ^\[ ]]; then
                interesting_field=0
            fi
        fi
        [[ $interesting_field -eq 1 ]] && [[ $key == "Name" ]] && echo $val
    done < $file
done

But this does not take into account shortcuts that are hidden from being showed in Dash. Someone with better understand of .desktop spec might want to further expand this code to exclude those kinda of shortcuts

Edit : another attempt, with Python

#!/usr/bin/python

from os import listdir
from os.path import isfile, join
import ConfigParser

SHORTCUTDIR = "/usr/share/applications/"

shortcuts = [ file for file in listdir(SHORTCUTDIR) if isfile(join(SHORTCUTDIR, file)) and file.endswith(".desktop") ]
dash_shortcuts = []

for f in shortcuts:
    c = ConfigParser.SafeConfigParser()
    c.read(SHORTCUTDIR + f)

    try:
        if c.getboolean('Desktop Entry', 'NoDisplay') is True:
            continue
    except ConfigParser.NoOptionError:
        pass

    try:
        if "unity" in c.get('Desktop Entry', 'NotShowIn').lower():
            continue
    except ConfigParser.NoOptionError:
        pass

    try:
        if "unity" not in c.get('Desktop Entry', 'OnlyShowIn').lower():
            continue
    except ConfigParser.NoOptionError:
        pass

    dash_shortcuts += [ c.get("Desktop Entry", "Name") ]

for s in sorted(dash_shortcuts, key=str.lower):
    print s
Flint
  • 3,211
  • 3
    You should really expand your answer to be more of an answer. – Seth Mar 16 '14 at 17:35
  • @Seth I posted too soon, sorry. I was scratching my head figuring out how to parse ini with bash – Flint Mar 17 '14 at 04:16
  • @AvinashRaj I wish it's that simple but that's not proper way to parse ini. The code will explode and throw noises if there are more than one Name entries in .desktop you're parsing, which always the case. Also you shouldn't assume all the lines you're interested with will be on fixed line number – Flint Mar 17 '14 at 04:25
  • @AvinashRaj Still bad :P You didn't take into account that Name option could be outside that range of line number, especially with lot of options or blank lines under [Desktop\ Entry ]. And .desktop file is an ini file – Flint Mar 17 '14 at 04:45
0

If you need list of applications shown when you hit Super+A, you can use ls /usr/share/applications. The only thing you should do is replace .desktop ending which is quite simple task. I do it with sed:

ls /usr/share/applications | sed s/.desktop// - > installed-apps.txt

But you can do it after you received the list using the text editor.

Danatela
  • 13,414
0

The questioner wants to list the names of all installed "apps".

Regarding apps with .desktop files:

  • the answer by Danatela deals with apps that have .desktop files in /usr/share/applications
  • as pointed out by Radu, apps with .desktop files may also be found in ~/.local/share/applications
  • at this point, it may be noted that apps with .desktop files can have two names
    • one "name" is available by querying the Dash in Unity or from menus in Xubuntu (for example). This name is derived from the Name= line in the respective .desktop file. One example is "Character Map".
    • the other "name" is the one to be used when running the app from the terminal and is the first word after Exec=. In the case of "Character Map", that would be gucharmap.
  • the two names (and the .desktop file) could be related using:
    • sed -ns '1F;/^\[Desktop Entry\]/,/^\[/{/^Name=/p;/^Exec=/h};${z;x;G;p}' /usr/share/applications/*.desktop
    • and
    • sed -ns '1F;/^\[Desktop Entry\]/,/^\[/{/^Name=/p;/^Exec=/h};${z;x;G;p}' $HOME/.local/share/applications/*.desktop

Regarding apps without .desktop files:

Depending on how one defines "app", some don't have .desktop files.

  • would something like conky, poppler-utils, qpdf, xdotool and wmctrl be considered "apps"? How are these to be identified and listed by their names (assuming one has installed them)?
  • What about awk, find, grep, ls and sed to name some more? Are they apps or are they not?

If anything that has a command is thought of as an app, then Linux command to list all available commands and aliases and this answer there will help identify them.

DK Bose
  • 44,703