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:

3 Likes

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

More info here:

14 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”

1 Like

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: > debian - How to show the number of installed packages - Unix & Linux Stack Exchange 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.

1 Like

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

this should help

Big HELP :+1:

Apt list --installed | wc

When I tried to enter -1 or -|
The system didn’t recognize the command
Edit: (in the next section, the specify it as “-l” AKA lowercase L. Didn’t get to try that one)

The output also listed 3 numbers:
738 2949 55881

Subtracted 1 from the first number and got the answer, though I still don’t know why 3 numbers were listed.

Also, I’d love to know how to use this information in a theoretical attack

3 Likes

+1 for me. I tried ```
dpkg --list | wc --lines which gave me 748. Im not sure what the difference is.

This worked for me
dpkg -l | grep -c ‘^ii’

dpkg -l | grep ^ii | wc -l

I tried all options and receive the error. I enter also listing the files on /var/lib/dpkg/info

thanks g i was stuck there a min or 2 but i don’t get why i must subtracted 1 for the first number

using apt list --installed | wc --lines will always give you incorrect answer cause it add a line before printing actual installed packages.

using dpkg -l | grep '^ii'

will show you the exact count

does anybody know what the ^ does? i can’t find the answer online.

never mind, i found it:
^ (caret)
means “the beginning of the line”. So “^a” means find a line starting with an “a”.

The aim behind the question is to use the different commands to achieve a one-liner:

apt list --installed | grep installed 1> stdin.txt && wc -l stdin.txt