Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Size of all installed packages.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Cocobo-1
Apprentice
Apprentice


Joined: 18 Dec 2003
Posts: 166
Location: Sweden

PostPosted: Fri May 26, 2006 2:26 pm    Post subject: Size of all installed packages. Reply with quote

Are there some way to get the size of all installed packages. I know about equery size but it only gives me the size for one package. I want a list sorted by size.

This must be a common question but I cant find an answer on the forums.
_________________
Professor: "Good news, everyone. Several years ago I tried to log onto AOL, and
it just went through. Whee! We're online."
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7394
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri May 26, 2006 5:09 pm    Post subject: Reply with quote

Not too common, I think, but it can be solved incrementally with existing *nix tools. It's not hard but there are several steps. Note that I'm using my steps below to figure out what needs to be done to implement your requirement, and to teach a little bit. Only the final command at the very bottom of this post needs to be run to get the job done.

First, use equery to discover a list of installed packages and determine what the equery output looks like when piped:
Code:
equery list -i | less
which produced output something like the following:
Code:
 * installed packages
app-admin/eselect-1.0
app-admin/logrotate-3.7.1-r2
app-admin/perl-cleaner-1.03
app-admin/showconsole-1.07
app-admin/sudo-1.6.8_p9-r2
...
Note that useful utilities often omit special formatting when they see that their standard output has been redirected, which is why I piped the output to less: just to see what happened so that I could design the next step properly.

Next, use awk to get rid of that pesky first line and then pipe the result of that into xargs to run equery size against all of those packages (again piped to less to see what the piped output looks like):
Code:
equery list -i | awk 'NR > 1' | xargs -i equery size ={} | less
This produced output something like:
Code:
app-admin/eselect-1.0: total(64), inaccessible(0), size(147665)
app-admin/logrotate-3.7.1-r2: total(17), inaccessible(0), size(39631)
app-admin/perl-cleaner-1.03: total(7), inaccessible(0), size(14738)
app-admin/showconsole-1.07: total(28), inaccessible(0), size(54142)
app-admin/sudo-1.6.8_p9-r2: total(35), inaccessible(0), size(308604)
...

Okay, now we're getting somewhere. Use another relatively short awk script to format the data for sorting. The script is getting a little cumbersome for the command line so I put it into a file. I've named the file "trim.awk":
Code:
#!/bin/awk
#
#   Format the output of "equery size ..." for sorting.
#
{
    # Get rid of the trailing ':' character.
    Field1 = substr($1, 1, length($1) - 1);

    # Get rid of the bracketing 'size()' characters.
    Field2 = substr($4, 6, length($4) - 6);

    printf "%10u %s\n", Field2, Field1;
}

I took the liberty of formatting the numbers in a right-justified fashion so that the final output would come out nice. Now we can add this script to the command line and pipe that output into sort:
Code:
equery list -i | awk 'NR > 1' | xargs -i equery size ={} | awk -f trim.awk | sort -k1
which produces nice sorted, formatted output:
Code:
         0 virtual/libiconv-0
         0 virtual/libintl-0
         0 virtual/libstdc++-3.3
         0 virtual/perl-MIME-Base64-3.07
         0 virtual/perl-Storable-2.15
         0 virtual/perl-Test-Simple-0.62
         0 virtual/qmail-1.03
      1125 sys-apps/coldplug-20040920-r1
      1491 sys-apps/hotplug-base-20040401
       ...
  39823758 dev-db/mysql-4.1.19
  44457644 dev-lang/perl-5.8.8-r1
  65618531 sys-devel/gcc-4.1.0-r1
  73195176 app-editors/emacs-cvs-22.0.50-r1
 226702589 sys-kernel/reiser4-gentoo-sources-2.6.16-r7

The command line is such a mouthful that I would be tempted to put it in a script file unless I were only using it once. Also note that each "equery size" takes a while, so the actual runtime of this command is pretty long.

And there you have it. (Reversing the sort order is left as an exercise for the student. :) )

You can look at the man pages for the individual utilities to learn what's going on. Also, learning (in this approximate order) grep, awk, and sed, will make your life a lot easier. I admit that there's a fair amount to learn.

Good luck.

- John


Last edited by John R. Graham on Fri May 26, 2006 9:23 pm; edited 4 times in total
Back to top
View user's profile Send private message
think4urs11
Administrator
Administrator


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Fri May 26, 2006 5:41 pm    Post subject: Reply with quote

a) rename /usr/portage/distfiles (so you still have it after this test)
b) emerge -evp world
c) check Total size of downloads
d) rename back a)

there's even that one (german): https://forums.gentoo.org/viewtopic-t-448337.html
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7394
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri May 26, 2006 5:52 pm    Post subject: Reply with quote

Wow, hadn't thought of that!

Think4UrS11, although admittedly much faster (very much faster), your method only shows the size of the distfiles for the installed packages, not the size of the installed packages. The distfiles are typically smaller because they are compressed. The command equery size appears to show the actual size of the installed package.

- John
Back to top
View user's profile Send private message
omp
Retired Dev
Retired Dev


Joined: 10 Sep 2005
Posts: 1018
Location: Glendale, California

PostPosted: Fri May 26, 2006 5:59 pm    Post subject: Reply with quote

john_r_graham wrote:
The distfiles are typically smaller because they are compressed.

Shouldn't it be the other way around since distfiles has the source, which is usually larger than the installed binaries?
_________________
meow.
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7394
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri May 26, 2006 6:09 pm    Post subject: Reply with quote

I understand the point. Apparently uncompressed binaries trump compressed source. I did some limited empirical checking and here's what I got:
Code:
ceres ~ # equery size gcc
[ Searching for packages matching gcc... ]
* size of sys-devel/gcc-4.1.0-r1
           Total files : 678
           Total size  : 64080.60 KiB
ceres ~ # cd /usr/portage/distfiles
ceres distfiles # ls -l gcc-4.1.0*
-rw-rw-r-- 1 root portage    17987 Apr 12 00:08 gcc-4.1.0-patches-1.2.tar.bz2
-rw-rw-r-- 1 root portage    18741 Apr 23 04:08 gcc-4.1.0-patches-1.3.tar.bz2
-rw-rw-r-- 1 root portage    22828 May 13 17:08 gcc-4.1.0-patches-1.4.tar.bz2
-rw-rw-r-- 1 root portage    20238 Mar 11 13:08 gcc-4.1.0-uclibc-patches-1.1.tar.bz2
-rw-rw-r-- 1 root portage 38639061 Mar  1 16:03 gcc-4.1.0.tar.bz2

Almost twice the storage installed as compared to the distfiles. Anyway, my point should have been that the two methods return fundamentally different results and it depends on which one you're interested in.

- John
Back to top
View user's profile Send private message
toralf
Advocate
Advocate


Joined: 01 Feb 2004
Posts: 2614
Location: Hamburg/Germany

PostPosted: Sun Jun 25, 2006 9:23 am    Post subject: Reply with quote

john_r_graham wrote:
Code:
equery list -i | awk 'NR > 1' | less
Code:
equery --quiet
and you don't need the awk
Back to top
View user's profile Send private message
nixnut
Administrator
Administrator


Joined: 09 Apr 2004
Posts: 10973
Location: the dutch mountains

PostPosted: Sun Jun 25, 2006 11:02 am    Post subject: Reply with quote

qsize (part of portage-utils) will tell you the size of the installed packages: qsize -aSm
_________________
Please add [solved] to the initial post's subject line if you feel your problem is resolved. Help answer the unanswered

talk is cheap. supply exceeds demand
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7394
Location: Somewhere over Atlanta, Georgia

PostPosted: Sun Jun 25, 2006 11:46 am    Post subject: Reply with quote

toralf wrote:
Code:
equery --quiet
and you don't need the awk
Cool! Thanks.

You can also stuff it all on the command line by using Perl instead of AWK:
Code:
equery -q list -i | xargs -i equery size ={} | perl -ne 'm/^(.*?):.*size\((.*)\)/; printf "%10u %s\n", $2, $1;' | sort -k1
but I despair thinking about explaining that to someone who is just setting out to learn or recommending it as a basic productivity tool for Linux.

"Learning linear algebra and quantum mechanics will make your life a lot easier." :lol:

- John


Last edited by John R. Graham on Mon Feb 19, 2007 8:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7394
Location: Somewhere over Atlanta, Georgia

PostPosted: Sun Jun 25, 2006 12:02 pm    Post subject: Reply with quote

nixnut wrote:
qsize (part of portage-utils) will tell you the size of the installed packages: qsize -aSm

Very cool. I'm learning all the time.

- John
Back to top
View user's profile Send private message
TomWij
Developer
Developer


Joined: 04 Jul 2012
Posts: 1339

PostPosted: Sat Dec 28, 2013 1:17 pm    Post subject: Reply with quote

Was looking for this; to do it with gentoolkit, nowadays you can do something like this:

Code:
equery size '*' | sed 's/\(.*\):.*(\([0-9]*\))$/\2 \1/' | sort -n | numfmt --to=iec-i



  • `equery size '*'` gets a list of all packages; when a pipe is present, the information will be put on one line.
  • `sed 's/\(.*\):.*(\([0-9]*\))$/\2 \1/'` rewrites the lines to first list size and then the package.
  • `sort -n` will do a numerical sort.
  • `numfmt --to=iec-i` will convert the size to a human readable format.
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7394
Location: Somewhere over Atlanta, Georgia

PostPosted: Sat Dec 28, 2013 2:05 pm    Post subject: Reply with quote

Hah. True. But when this thread was written, equery didn't support any sort of wildcard syntax. Brian did a good job on the rewrite.

- John
_________________
This space intentionally left blank.


Last edited by John R. Graham on Sat Dec 28, 2013 6:36 pm; edited 1 time in total
Back to top
View user's profile Send private message
dol-sen
Developer
Developer


Joined: 30 Jun 2002
Posts: 2503
Location: Richmond, BC, Canada

PostPosted: Sat Dec 28, 2013 4:28 pm    Post subject: Reply with quote

Actually, I didn't do the wildcard upgrades... All kinds of other stuff in the rewrite, like the separation of the working code and the output of it. :)

This type of report would belong to the enalyze module I started in gentoolkit.
Enalyze does whole installed pkgs analysis. Equery is more for individual pkg or parameter reporting.

It would also be faster, since it could use the equery sub-module directly. no need to re-initialize portage and gentoolkit modules every time equery was called.
_________________
Brian
Porthole, the Portage GUI frontend irc@freenode: #gentoo-guis, #porthole, Blog
layman, gentoolkit, CoreBuilder, esearch...
Back to top
View user's profile Send private message
TomWij
Developer
Developer


Joined: 04 Jul 2012
Posts: 1339

PostPosted: Sat Dec 28, 2013 4:53 pm    Post subject: Reply with quote

I still feel bad about `equery size '*' | sed 's/\(.*\):.*(\([0-9]*\))$/\2 \1/'`, isn't there a more efficient way to pick the package ATOM and size columns? Should equery perhaps have not output the ":" and "size()"?
Back to top
View user's profile Send private message
wangbj
n00b
n00b


Joined: 08 Oct 2013
Posts: 2

PostPosted: Wed Jan 29, 2014 10:23 pm    Post subject: Reply with quote

qsize -a | sort -n -k 6
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum