4

Can I retrieve a list of the sizes of MacPorts installed packages?

Yes, I know they are compiled from sources, but if a list of generated files is known, it should be computable anyway.

6 Answers 6

3

You could make use of port build in command contents, which gives you the oportunity to do things like that:

port contents --size depof:python27

Grep the lines you need and do the maths :-)

Update: found answer here at guide.macports.

While reading a bit deeper, I found this

port space --units MB --total thisport

which is much more handy then calculating the sum of the size of each file inside a port.

2
  • I can't test it any more, so I'll just trust this to be correct.
    – o0'.
    Jun 19, 2015 at 12:11
  • 1
    @Lohoris : much appreciated. Added link where I found this. Jun 19, 2015 at 14:24
2

Using the command:

du -sh /opt/local/var/macports/software/*

echos back all directories and sizes of your installed ports.

Use the command:

port -d echo installed

echoes a listing of the ports installed.

2
  • Oh. I didn't know they were neatly installed in separate directories :)
    – o0'.
    Oct 8, 2011 at 12:13
  • Oh, they aren't. In those directories I just have the tarballs. I want to know the full current installed size.
    – o0'.
    Oct 8, 2011 at 12:16
2

To get each port along with a total of all ports just type port space installed

Example output (partial):

57.425 KiB xorg-renderproto @0.11.1_0
7.189 KiB xorg-scrnsaverproto @1.2.2_0
49.408 KiB xorg-videoproto @2.3.3_0
849.766 KiB xorg-xcb-proto @1.12_1
66.130 KiB xorg-xcb-util @0.4.0_0
143.412 KiB xorg-xextproto @7.3.0_0
18.946 KiB xorg-xf86vidmodeproto @2.3.1_0
5.789 KiB xorg-xineramaproto @1.2.1_0
469.177 KiB xorg-xproto @7.0.31_0
171.815 KiB xrender @0.9.10_0
1.344 MiB XviD @1.3.4_0
1.575 MiB xz @5.2.2_0
3.102 MiB yasm @1.3.0_0
707.211 KiB zlib @1.2.8_0
3.645 GiB total
1
  • If you want to sort by package size use port space --units MB installed | sort -n. May 22, 2019 at 19:00
1

To list the dependencies as a hierarchy

psd() {
port rdeps $1 2>/dev/null | sed -E "1 s/.*of (.*) @.*/\1/" |
while IFS= read -r line
    do
        port_name="$(port space --total $line 2>/dev/null | cut -d ' ' -f 1-2)"
        port_size=${port_name% *}
        port_unit=${port_name#* }
        printf "%-30s%12.2f %s\n" "$line" "$port_size" "$port_unit"
    done
}

Example

$ psd mosh
mosh                                895.03 KiB
  pkgconfig                         629.39 KiB
    libiconv                          6.27 MiB
      gperf                           0.00 B
  ncurses                            15.17 MiB
  protobuf-cpp                       44.11 MiB
    autoconf                          0.00 B
      xz                              1.68 MiB
        gettext                      24.82 MiB
          expat                       1.11 MiB
    automake                          0.00 B
    libtool                           4.19 MiB
    zlib                            738.74 KiB
  openssl                            17.50 MiB
  p5.22-getopt-long                 132.63 KiB
    perl5.22                         54.52 MiB
      gdbm                          553.91 KiB
  p5.22-io-socket-ip                 64.05 KiB

Adjust the length of the formatted output, 30 in my example, as needed.
If you want the output truncated or rounded, see here.

To list the grand total of the above hierarchy

alias pst='_() { port rdeps $1 2>/dev/null | cut -d : -f 2 | xargs port space --units MiB --total $1 2>/dev/null ; } ; _'

Example

$ pst mosh
172.312 MiB total

You might want to check port help space.

I guess you could add coloring and ordering to the output.

0

Well, by default they install to /opt/local so it should be as easy as cd /opt/local && du -sh * to get a list of the file sizes. Not sure if it's built into MP by default to give you overall sizes

3
  • Why not just du -sh /opt/local?
    – EmmEff
    Oct 7, 2011 at 15:06
  • That works as well, I like being in the directory to start tinkering so go down the cd path ;) Oct 7, 2011 at 15:14
  • ???. I'd like to know the single package size, not the sum of all the macports.
    – o0'.
    Oct 8, 2011 at 12:16
0

If you wanna get the size of a specific package :

port space [package name]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .