Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
I can't test it any more, so I'll just trust this to be correct. – o0'. Jun 19 '15 at 12:11
@Lohoris : much appreciated. Added link where I found this. – Marco M. von Hagen Jun 19 '15 at 14:24

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.

share|improve this answer
Oh. I didn't know they were neatly installed in separate directories :) – o0'. Oct 8 '11 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 '11 at 12:16

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

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

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
        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"


$ 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 ; } ; _'


$ 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.