Q: How to find number of packages installed?

I’m stuck in the section “File Descriptors and Redirections” of the academy on the question “How many total packages are installed on the target system?”.

I’ve tried “apt list”, “apt list --installed”, “dpkg -l”, “dpkg-query -l” and “dpkg-query -W” and piped the result of them to wc. But none of the answers seem to be correct.

Could anyone please lead me in the right direction?

Also, I’m not sure if it’s ok to post this Q with the commands I already tried, if that’s the case feel free to remove it. :wink:

1 Like

This one did it for me
dpkg -l | grep -c '^ii'

More info here:

3 Likes

Aahhh… Of course… I also counted the headline… Doh. Thx. :smiley:

1 Like

You can try using the ‘apt’ package manager to check the installed ones. Then, use ‘grep’ to find it.

1 Like

smth like `apt list --installed | grep -c “installed”

COMANDO GREP

Podrias hacer asi

grep -c : para mostrar solo los resultados que conincidan con algun patron .

Entonces quedaria asi

dpkg -l | grep -c “installed”

En este caso en especifico vemos que el patro de grep -c es todos los paquetes que contengan el “tag” de "installed " o instalados .

> @xhiwe said: > This one did it for me > dpkg -l | grep -c ‘^ii’ > > More info here: > https://unix.stackexchange.com/a/8053/271004 This helped me a great deal, thank you. I was stuck on this one for a min lol

1 Like

I got stuck too in this lesson but at the end I figured even "apt list --installed | wc -l " works too! but it adds one to the actual output. cuz wc counts the lines and the first line of the output of “apt list --installed” is Listing…done.

debian - How to show the number of installed packages - Unix & Linux Stack Exchange

this should help

Big HELP :+1: