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.
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.
Sign up to join this communityYou 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.
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.
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
port space --units MB installed | sort -n
.
May 22, 2019 at 19:00
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.
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