apt list --installed | grep installed 1> stdin1.txt && wc -l stdin1.txt
apt list --installed | grep -c installed
Hey, so after a little help, I used the command: apt list --installed |grep c | wc -l
and I got the right answer. However, I’m confused on why we use the letter “c” for grep?
Hey I tried your command but i doesn’t work for me. i tried all the commands of this topic…
can somebody tell the difference between these 2 command :
apt list --installed | wc -l // wrong but show result
dpkg -l | grep ^ii | wc -l //correct
i dkn why when i use apt list --installed | wc -l
is wrong but i use dpkg -l | grep '^ii' | wc -l
is true
I have tried all the suggestions shared on this page, but none of them have worked.
In my case the correct answer is 737. I found it by trying number after number one by one.
apt list --installed | grep -c “installed”
Just a theory (that I developed after speaking with ChatGPT for a while), but i think it’s because that way we exclude the header:
Listing… (THIS)
package1/version
package2/version
package3/version
…
Since every one of the packages have the letter “c” on the name. Next line is from ChatGPT:
Using
grep c
inapt list --installed | grep c | wc -l
is an unintended but effective way to exclude the header line and count only the installed packages. However, it’s important to note that this method relies on the assumption that every package name contains the letter “c”. While generally true for package names in Linux distributions, it’s not a foolproof method and may not work in all cases or across different systems. For robustness, especially in scripting or automation, it’s better to explicitly exclude the header line usinggrep -v '^Listing'
to ensure accurate counting of installed packages.
lol same i opened it in nano and saw … lines and wrote that but it says listing in the first line so had to subtract 1
can you please explain this command?
dpkg --get-selections |grep -w “install” |wc -l
removed the head and just included the “wc -l”
Feel like HTB doesn’t teach you what you need but, to have you research what they ask lol
There are many ways to solve this :
Command 1 -
dpkg -l | grep -c 'ii'
Command 2 -
dpkg -l | grep -i 'ii' | wc -l
Correct Answer : 737
dpkg -l → Finding all installed pkg
| → Pipe
grep -c ‘ii’ → Count the files.
dpkg --get-selections | grep -v deinstall | wc -l
dpkg --get-selections
: Lists all packages along with their installation status.grep -v deinstall
: Filters out packages that are marked for removal (but not removed yet).wc -l
: Counts the lines.
Another aproach.
apt list --installed | grep installed | wc
apt gives you the list of packages, pipe | then grep only the installed, pipe | then count excluding the first line.
it worked, thnx