I've been trying to figure out package management in debian a little better.

I figured out that you can list all the packages on your system by using the "apt-cache pkgnames" command:

root@t500:/etc# apt-cache pkgnames | less

However, when I try to look up additional information about the packages in dpkg, the same package names are not listed:

root@t500:/etc# dpkg-query -W meep
No packages found matching meep.

root@t500:/etc# dpkg-query -W darkice
No packages found matching darkice.

I had assumed that apt and dpkg they would at least utilize the same package names, is that not the case?

Is there a way of figuring out what the dpkg name of an apt package is?

  • Just one comment, do not use root all the time...
    – Braiam
    Dec 2, 2013 at 21:29

2 Answers 2


It's the same name, apt is just a frontend to dpkg. The issue here is that the commands don't do what you thing they do. As explained in man apt-cache:

   pkgnames [prefix]
       This command prints the name of each package APT knows. The
       optional argument is a prefix match to filter the name list. The
       output is suitable for use in a shell tab complete function and the
       output is generated extremely quickly. This command is best used
       with the --generate option.

       Note that a package which APT knows of is not necessarily available
       to download, installable or installed, e.g. virtual packages are
       also listed in the generated list.

So, apt-cache pkgnames lists all packages available to the system, irrespective of whether those packages are installed or not.

If you want to list installed packages only, you could use dpkg -l or dpkg-query -l:

   -l, --list [package-name-pattern...]
          List packages matching given pattern. If no package-name-pattern
          is  given,  list all packages in /var/lib/dpkg/status, excluding
          the ones marked as not-installed (i.e.  those  which  have  been
          previously  purged). 

This means that it will also list those packages that have been removed if their configuration files are still present, i.e. if they were not purged. The second column of the dpkg-query -l output is the package status which can be any of

          Package status:
            n = Not-installed
            c = Config-files
            H = Half-installed
            U = Unpacked
            F = Half-configured
            W = Triggers-awaiting
            t = Triggers-pending
            i = Installed

So, to find those packages that are currently installed, you will want to select those whose status is i. To do that, simply grep for lines whose 1st character is anything and whose second is i:

dpkg-query -l | grep '^.i'

You can easily check that the two commands are different and that apt-cache returns thousands more results than dpkg. For example, on my system:

$ dpkg-query -l | grep '^.i' | wc -l
$ apt-cache pkgnames | wc -l
  • Super helpful, thanks. Your pkgnames comes up with nearly 40k results, while mine only comes up with around 28k. Would that be due to differences in our sources.list files?
    – some1
    Dec 2, 2013 at 22:00
  • 1
    @some1 yes, exactly. Different sources mean different packages.
    – terdon
    Dec 2, 2013 at 22:03

The problem is that you need to establish a 'pattern' (with quotes) instead of just writing the name:

$ dpkg-query -W 'samba'
$ dpkg-query -W 'samba*'
samba-common    2:3.6.9-1ubuntu1.1
samba-common-bin    2:3.6.9-1ubuntu1.1

That's why no package appear:

$ dpkg-query -W 'rkhunter' 
rkhunter    1.4.0-2

Other things that may work:

dpkg-query -W '*a'
dpkg-query -W 'a*b*'
dpkg-query -W '?a*'


Normal shell wildchars are allowed in package-name-pattern. Please note you will probably have to quote package-name-pattern to prevent the shell from performing filename expansion.

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.