13

What is the Debian equivalent of Fedora's yum list installed | grep wc --lines?

0

8 Answers 8

13

According to this thread:

To list installed packages:

dpkg --list | wc --lines

To see if a package is installed:

dpkg --list | grep package
1
  • 2
    You're including the header lines and some non-installed packages (e.g. rc (uninstalled but with config files left over)) in your count. Feb 24, 2011 at 23:13
12
dpkg -l | grep -c '^ii'

There are subtle variants like dpkg -l | grep -c '^?i' if you want to include packages that are installed but whose removal you've requested. Another way is

aptitude search '~i' |wc -l

You can even poke directly into the dpkg database:

sh -c 'set /var/lib/dpkg/info/*; echo $#'

This one includes packages that are not installed but that have configuration files left over; you can list these with dpkg -l | grep '^rc'.

2

What I've been using is:

dpkg --get-selections | wc --lines

This will give you the number of installed packages.

If you want to find if a particular package is installed, use:

dpkg --get-selections | grep <package>

I believe that this will solve Gilles' complaint about including other, non-installed packages.

2

apt list --installed | grep -c 'installed'

#apt list --installed=> shows all packages> we grep the results from the list only for the lines containing the string "installed"

For me, this command worked

1

dpkg -l is nice but I actually find myself using apt-show-versions (not installed by default on Debian; install the package of the same name) a lot instead, especially when I want to process the output further (dpkg tries to be too clever with line wrapping).

1

Synaptic, a GUI package manager, displays the count at the bottom of its main window.

enter image description here

0

If you want an exact count of packages, you should not count the header lines output by dpkg-query -l, so you need a pattern to match lines starting with ii. The following one-liner gives you the number of lines starting with ii and therefore the number of installed packages:

dpkg-query -l | grep "^ii" | wc -l 

This gives the same output as

 dpkg --get-selections | grep "[[:space:]]install" | wc -l

The grep pattern in the second command ignores lines that contain the string "deinstall" in the output of dpkg --get-selections.

-1

For instace, you can do this:

dpkg-query -l | nl | tail -1 | awk '{print $1}'
2
  • OK, it's true that nl | tail -1 | awk '{print $1}' will report the number of lines in its input (except, if there is no input, it will say nothing instead of reporting 0) — but why would you recommend such a kludge when other answers are already using wc -l? Jul 29, 2016 at 1:58
  • That's funny cause i didn't read previous answers! @G-Man ...but this still remains a good answer. Aug 7, 2016 at 2:04

You must log in to answer this question.

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