What is the Debian equivalent of Fedora's
yum list installed | grep wc --lines?
According to this thread:
To list installed packages:
dpkg --list | wc --lines
To see if a package is installed:
dpkg --list | grep package
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'.
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.
Synaptic, a GUI package manager, displays the count at the bottom of its main window.
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