Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using Kubuntu. I'd like to get a list of installed packages on my system, and in particular to have them sorted by category, i.e. as seen in Muon Package Manager, in the category filter tab. For a visual reference, it the left part of the window in the following image.

enter image description here

From inside Muon there is an option to export a list of installed packages in the File menu, but it just exports a plain list (I think that it executes the dpkg --get-selections command) and that's not what I'm looking for.

I tried to look in the man pages of dpkg, dpkg-query, apt and apt-get but I failed to find any useful information.

The only clue I got is that the manual of dpkg-query states that it is possible to sort the output by using some command options, but I haven't found how to sort by category.

Any clue?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can indeed do this using dpkg-query and a couple of other tools:

dpkg-query -Wf='${package}\t${Section}\t${status}\n' | grep installed | 
  gawk '{print $2"\t"$1}' | sort 


  • dpkg-query -Wf='${package}\t${section}\t${status}\n' : This command will list all packages (-W), as package name< TAB >package section< TAB >package status. From the dpkg-query man page:

    -f, --showformat=format
          This  option  is  used  to specify the format of the output --show 
          will produce. The format is a string that will be output for each package 

    So, this command alone produces output like this:

    $ dpkg-query -Wf='${package}\t${Section}\t${status}\n' | head
    a2ps    text    install ok installed
    abiword editors install ok installed
    abiword-common  editors install ok installed
    abiword-plugin-grammar  editors install ok installed
    abiword-plugin-mathview editors install ok installed
    accountsservice admin   install ok installed
    acl utils   install ok installed
    acpi    utils   install ok installed
    acpi-support-base   admin   install ok installed
    acpid   admin   install ok installed
  • grep installed : selects only those lines describing packages whose status is installed.

  • gawk '{print $2"\t"$1}' : Use gawk to print only the two fields we are interested in (package name and section), to make the output easier to read and sort, print the Section first and the package name second.

  • sort : Since the section is now the first field, a simple sort is enough to sort the packages by section.

The final output looks like this:

admin   accountsservice
admin   aptdaemon-data
editors libreoffice-impress
fonts   fonts-telu
games   enemylines3
games   enemylines7
gnome   cinnamon
libdevel    libxmu-dev
libs    libapt-pkg4.12
oldlibs hpijs
python  python-gi-cairo
share|improve this answer
Thank you, superb answer! It seems that I was looking for a "category" field while it was in fact "section" the option I needed. –  Sekhemty Apr 20 '13 at 14:18
bravo terdon, super cool solution with comprehensive details. –  xpt Apr 20 '13 at 14:46

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.