On many distributions and the BSDs there are ways to determine the number of packages in the distro's enabled repositories, e.g. on FreeBSD you could use pkg stats, is there such a way with Ubuntu? I know how to count the number of installed packages, namely using:

dpkg -l | wc -l

which on my Ubuntu 18.04 Bionic Beaver (developmental version) system returns 1962 (and yes I know not to rely on the stability of a developmental release, as things can and often do break, this is just a system for me to satisfy my curiosity about the new release to come), but how do I count all packages in its enabled repositories?

I would imagine that apt-cache search "*" would return a list of all available packages, which I could then count with wc -l but no it returns:

E: Regex compilation error



apt-cache has a function to list all packages

sudo apt-cache pkgnames | wc -l

returns 58218 packages with main, universe, multiverse, restricted and backports enabled on artful.

  • Oh rofl, I thought there was a search element to it. Sorry, nvm. It works. – BH2017 Feb 16 '18 at 12:42

You can use:

$ apt-cache stats
Total package names: 73411 (1.468 k)

to get that and way more information about the repositories enabled that you probably care about.

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.