how many packages?

Forum rules
General talk about software - if the program is not in the repos, please links to the developer's page or github.
pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

how many packages?

Unread post by pidsley » Mon Jul 07, 2014 3:53 am

Someone asked me about adding a package count to env-info, and I'm probably not going to do this because it would require conditional code based on the distro you are using. But it did make me investigate how easy this is to do in different distros, and looking at the output might make you reconsider some things you have installed and no longer use.

I've only investigated three distros so far, and here is one command to give you a list, and another expression to give you just the count for each of the three. I find these lists very interesting and useful for pruning crap you installed and then forgot about.

Debian

Code: Select all

dpkg -l | grep ^ii | less  # list
dpkg -l | grep ^ii | wc -l # count
Arch

Code: Select all

pacman -Q | less  # list
pacman -Q | wc -l # count
CRUX

Code: Select all

prt-get listinst | less  # list
prt-get listinst | wc -l  # count
Of course you can redirect the list output to a file instead of less, and as always I apologize if this has already been discussed elsewhere.

If you know you will always use env-info on a Debian system, feel free to hack the code. Just add a function like this:

Code: Select all

print-pkgcount() {
    count=$(dpkg -l | grep ^ii | wc -l)
    color_echo Packages $count
}
And then call the function in the list at the end, wherever you want the output, like this

Code: Select all

print-disk
print-mem
print-pkgcount
(edit) I do have a conditional version working now, but I still don't think I will add it to the main version of env-info. I'd like to keep that one simple. I may just use it in my experimental version of the script.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: how many packages?

Unread post by GekkoP » Mon Jul 07, 2014 8:43 am

Great stuff, thanks. I use somthing similar to list packages and do some cleaning every now and then. Might add it to env-info now.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: how many packages?

Unread post by rhowaldt » Mon Jul 07, 2014 1:28 pm

cool idea pidsley. i once built a bloat-script (bash script called bloat.py) that might benefit from this addition. that is, if somebody still uses it (Jules?)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: how many packages?

Unread post by machinebacon » Mon Jul 07, 2014 3:28 pm

yeah i do remember bloat.py, but haven't been using it for a while (but it was used for making the package list for base spins) - has helped a lot to keep dep. count low ;)
..gnutella..

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: how many packages?

Unread post by rhowaldt » Mon Jul 07, 2014 5:12 pm

well, for posterity (i believe the script was last posted on the *noob), here's the code. pids, if you mind this mucking up your thread, feel free to move it or talk sternly to me, but it seems relevant to me to post it here as well :)

Code: Select all

#!/bin/bash

# this script determines how bloated a certain package is.
# it will check for dependencies, then see how many already installed packages depend on those too (ie. 'useful dependencies'),
# then check how many packages in general depend on those, and attempt to pass some sort of judgment.

# DEPENDENCIES: bash, bc

if [[ $1 == "-h" ]]; then
	echo "bloat.py determines the bloatedness of a package relative to the current state of your system."
	echo "usage: bloat.py [package]"
	echo "a * in front of an entry means that package is installed on your system."
	echo "the note 'common' behind a package means that package has 1000+ other packages depending on it, and may therefore be considered a common package."
	echo "the dep and rdep columns show the dependencies and reversed dependencies of a package, and how many of them are installed on your system."
	exit 0
fi

# function for finding a value in an array
function contains() {
    local n=$#
    local value=${!n}
    for ((i=1;i < $#;i++)) {
        if [ "${!i}" == "${value}" ]; then
            echo "y"
            return 0
        fi
    }
    echo "n"
    return 1
}

bytesize_total=0
dep_full=($(apt-cache -i depends "$1" | cut -d: -f2- | tail -n +2))
depi_full=($(apt-cache -i depends --installed "$1" | cut -d: -f2- | tail -n +2))
dep_perc=$(echo "scale=2; ${#depi_full[*]}/${#dep_full[*]}*100" | bc | sed "s/\.00$//")
echo
echo "$1 has ${#dep_full[*]} dependencies, of which ${#depi_full[*]} are installed ($dep_perc%)."
echo
printf '%-1s %-26s %-7s %-12s %-12s %-6s %-8s\n' "" "package" "size" "dep" "rdep" "% inst" "note"
printf '%-1s %-26s %-7s %-12s %-12s %-6s %-8s\n' "" "--------------------" "-------" "-----------" "-----------" "------" "--------"
for d in ${dep_full[*]}; do
	installed=""
	note=""
	bytesize=""
	size=""
	dep_tmp=($(apt-cache depends -i --no-pre-depends "$d" | cut -d: -f2- | tail -n +2))
	depi_tmp=($(apt-cache depends -i --no-pre-depends --installed "$d" | cut -d: -f2- | tail -n +2))
	rdep_tmp=($(apt-cache rdepends -i "$d" | tr -d ' ' | tail -n +2))
	rdepi_tmp=($(apt-cache rdepends -i --installed "$d" | tr -d ' ' | tail -n +2))
	rdep_perc=$(echo "scale=2; ${#rdepi_tmp[*]}/${#rdep_tmp[*]}*100" | bc | sed "s/\.00$//")
	bytesize=$(apt-cache show "$d" | grep "^Size" | cut -d: -f2- | tr -d ' ')
	
	if [[ bytesize -lt 1048576 ]]; then
		size="$(echo "scale=0; $bytesize/1024" | bc)Kb"
	else
		size="$(echo "scale=1; $bytesize/1048576" | bc)Mb"
	fi
	if [ $(contains "${depi_full[@]}" "$d") == "y" ]; then
		installed="*"
	else
		bytesize_total=$(($bytesize_total + $bytesize))
	fi
	if [ ${#rdep_tmp[*]} -ge 1000 ]; then
		note="common"
	elif [ ${#rdep_tmp[*]} -ge 100 ]; then
		note=""
	fi
	printf '%-1s %-26s %-7s %-12s %-12s %-6s %-8s\n' "$installed" "$d" "$size" "${#depi_tmp[*]}/${#dep_tmp[*]}" "${#rdepi_tmp[*]}/${#rdep_tmp[*]}" "$rdep_perc%" "$note"
done
echo
echo "additional bloat: $(echo "scale=0; ${#dep_full[*]}-${#depi_full[*]}" | bc) packages, $(echo "scale=2; $bytesize_total/1048576" | bc)Mb"
exit 0
it isn't very fast, simply because it takes a while to query apt-cache and such, but hey, it works (most of the time - still throws errors some time, never got around to fixing them).
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: how many packages?

Unread post by wuxmedia » Mon Jul 07, 2014 5:24 pm

not that i'm OCD, just wondering:

A bash script called "bloat.py" ?

I know, call it what you want...
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: how many packages?

Unread post by GekkoP » Mon Jul 07, 2014 5:29 pm

Oh yes, I used this one before:

Code: Select all

dpkg --get-selections | grep -v deinstall | less

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: how many packages?

Unread post by pidsley » Tue Jul 08, 2014 2:01 am

^ thanks! -- I learned something new about the mysterious world of dpkg.

Here is some conditional code for env-info -- add at your own risk (sorry bones, won't work for Slack)

Code: Select all

print-pkgcount() {
    count=0
    if [[ $(which prt-get 2>/dev/null) != "" ]]; then     # CRUX
        count=$(prt-get listinst 2>/dev/null | wc -l)
    elif [[ $(which dpkg 2>/dev/null) != "" ]]; then      # Debian 
        count=$(dpkg -l 2>/dev/null | grep ^ii | wc -l)
    elif [[ $(which pacman 2> /dev/null) != "" ]]; then   # Arch
        count=$(pacman -Q 2>/dev/null | wc -l)
    fi
    [[ $count != 0 ]] && color-echo Packages $count     # if $count is still zero i have no clue
}

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: how many packages?

Unread post by GekkoP » Tue Jul 08, 2014 8:25 am

^ thanks, I'll add it without caring about the risk! ;)

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: how many packages?

Unread post by rhowaldt » Tue Jul 08, 2014 9:06 am

@wux: the confusion is the point - unbloat your mind! let go of silly ideas! :D
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
archvortex
Uninstaller
Posts: 241
Joined: Sat Sep 07, 2013 2:41 pm
Location: Vancouver, Canada

Re: how many packages?

Unread post by archvortex » Tue Jul 08, 2014 1:42 pm

Linux BBQ
Unbloat your system .... Unbloat your mind
GUIs??? We don't need no stinkin' GUIs!!!
LinuxBBQ - No bloated bullshit to meet the needs of the less technical Linux user
Color is bloat

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: how many packages?

Unread post by bones » Tue Jul 08, 2014 3:20 pm

pidsley wrote:^ thanks! -- I learned something new about the mysterious world of dpkg.

Here is some conditional code for env-info -- add at your own risk (sorry bones, won't work for Slack)
No worries, I'll see if I can figure out what the equivalent for Slackware is, and post it here.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: how many packages?

Unread post by rhowaldt » Tue Jul 08, 2014 7:54 pm

There are two major products that came out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. ~Jeremy S. Anderson
good quote Boners! :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: how many packages?

Unread post by bones » Tue Jul 08, 2014 8:02 pm

^ Thought you might like that one! ;)

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: how many packages?

Unread post by machinebacon » Tue Jul 08, 2014 8:05 pm

Slack should show the number of installed packages like so:

ls /var/log/packages/ | sort | wc -l

Not including stuff that is installed via sbopkg (but that's no official anyway!)
..gnutella..

User avatar
elixir
Weight Watcher
Posts: 357
Joined: Fri Feb 21, 2014 8:25 am

Re: how many packages?

Unread post by elixir » Sat Jul 12, 2014 11:20 am

archvortex wrote:Linux BBQ
Unbloat your system .... Unbloat your mind
Simplicity is most creative :)
Out of the corner of your eye you spot him... Shia LaBeouf.

https://www.youtube.com/watch?v=o0u4M6vppCI

Post Reply