You are not logged in.

#1 2020-06-11 17:28:50

dpx
Member
Registered: 2017-01-09
Posts: 48

Cumulative package size

I am using this snippet to get nice list of all the packages I installed:

expac -HM '%n\t%G\t%w\t%m\t%d' $(comm -23 <(pacman -Qeq | sort) <(pacman -Qgq base-devel | sort)) | column -t -s $'\t' -o$' | ' | sort -t "|" -hk 4

I am also using pacgraph as another good tool to see sizes of my packages, pacgraph does include (sort of) cumulative sizes of packages plus their dependencies.

I would love to improve snippet above, to print package size with all its dependencies (and their sub-dependencies), so I can see how much each package weights. It is perfectly fine if package A and package B both include size of package C if they are dependent on it.

Any suggestions how to do it? Thanks.

Offline

#2 2020-06-11 17:41:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: Cumulative package size

How about this:

#!/bin/sh

for pkg in $(pacman -Qeq); do
   expac %m $(pactree -lu $pkg) | awk -v pkg=$pkg '
      { sum+=$1; }
      END { printf "%s\t%0.2f\n", pkg, sum / (1024 * 1024); }
   '
done | sort -nrk2 | column -t | head

This one goes against your criteria of a dependency being able to be a dependency of another package - but it answers a different question: how much space would be saved by removing a given package (the size of the package and it's dependencies that are not needed by anything else):

#!/bin/sh

for pkg in $(pacman -Qetq); do
	expac %m $(pacman -Rs --print --print-format %n $pkg) | awk -v pkg=$pkg '
		{ sum+=$1; }
		END { printf "%s\t%0.2f\n", pkg, sum / (1024 * 1024); }
	'
done | sort -nrk2 | column -t | head

Last edited by Trilby (2020-06-11 17:46:30)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2020-06-11 17:50:08

dpx
Member
Registered: 2017-01-09
Posts: 48

Re: Cumulative package size

Thank you,

pactree -lu

is exactly what I need, I can work from there. -u is magic I needed, wasn't aware it exists. If I make something useful I'll post here. How does it work on arch forum, should I mark thread solved or leave it for discussion?

Offline

#4 2020-06-11 17:56:55

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: Cumulative package size

If you came in looking for information and now have it, then you can mark this as SOLVED.  This probably shouldn't be in the pacman - while the input data may come from pacman, that's not the topic.

This could be well suited to programming and scripting if you just wanted help acheiving the goal which is SOLVED.  Or it could go to "community contributions" if you intend to develope the idea more and share useful tool with the community (which which case there'd be no reason to mark the thread as SOLVED).

I'll leave it to you to use the report button to ask a moderator to move the thread to whichever of those better suits your purpose.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2020-06-11 19:30:13

dpx
Member
Registered: 2017-01-09
Posts: 48

Re: Cumulative package size

This is exactly what I needed:

#!/usr/bin/env bash

# Equivalent of
# expac -HM '%n\t%G\t%w\t%m\t%d' $(comm -23 <(pacman -Qeq | sort) <(pacman -Qgq base-devel | sort)) | column -t -s $'\t' -o$' | ' | sort -t "|" -hk 4
# but with cumulative size per package

list=$(comm -23 <(pacman -Qeq | sort) <(pacman -Qgq base-devel | sort))

for pkg in $list; do
	size=$(expac %m $(pactree -lu $pkg) | awk '{s+=$1}END{printf "%0.2f MiB", s / (1024 * 1024);}')
	groups=$(expac %G $pkg)
	reason=$(expac %w $pkg)
	description=$(expac %d $pkg)
	printf "%s\t%s\t%s\t%s\t%s\n" "$pkg" "$groups" "$reason" "$size" "$description"
done | column -t -s $'\t' -o$' | ' | sort -t "|" -hk 4

I didn't use shell scripting for some time so it is using bash -- I could probably fall back to sh but run into few problems with $list. I'll ask moderator to move it to scripting. Very useful for me.

Cumulative mpv is 1067.10 MiB, not as lightweight as I thougt plus other surprises,

Offline

#6 2020-06-11 19:35:38

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: Cumulative package size

That's a lot of subshells and calls to expac inside the loop.  Wouldn't the following inside the loop have the same result:

        size=$(expac %m $(pactree -lu $pkg) | awk '{s+=$1}END{printf "%0.2f MiB", s / (1024 * 1024);}')
        expac "%n\t%G\t%w\t$size\t%d" $pkg

I'm also not sure why you include the install reason as a column as explicitly installed packages are the only input anyways.

Last edited by Trilby (2020-06-11 19:41:35)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2020-06-11 19:38:48

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Cumulative package size

Moving to Programming & Scripting.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#8 2020-06-12 07:06:27

dpx
Member
Registered: 2017-01-09
Posts: 48

Re: Cumulative package size

Trilby wrote:

That's a lot of subshells and calls to expac inside the loop.  Wouldn't the following inside the loop have the same result:

        size=$(expac %m $(pactree -lu $pkg) | awk '{s+=$1}END{printf "%0.2f MiB", s / (1024 * 1024);}')
        expac "%n\t%G\t%w\t$size\t%d" $pkg

I'm also not sure why you include the install reason as a column as explicitly installed packages are the only input anyways.

Being able to print $size directly from expac is a neat trick, didn't think that way. I am adding reason because I sometimes change initial $list query so it doesn't always contain 'explicit' only. Thanks.

Offline

Board footer

Powered by FluxBB