【问题标题】:How to get the size of the installed package via MacPort?如何通过 MacPort 获取已安装包的大小?
【发布时间】:2013-04-15 04:16:52
【问题描述】:

port installed 显示本地机器上所有已安装的包,但是有没有办法列出每个包的大小?谢谢!

【问题讨论】:

    标签: macports


    【解决方案1】:
    port space --units MB installed
    

    简单易用,自 2011 年 version 2.0 以来一直可用!

    【讨论】:

      【解决方案2】:

      我不相信 Macports 有内置命令来列出您的安装大小,但您可以这样做:

      在终端中试试这个命令:

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

      这将为您提供 /opt/local/var/macports/software/* 中每个包的大小,我相信是默认安装位置。

      显然,如果您将端口安装在其他可以使用的地方

       du -sh [directory]
      

      如果没有内置的 Macports 命令,这可能是您能做的最好的事情了。

      想到的另一种选择是创建一个脚本来获取

      的输出
       port installed
      

      并回显每次安装的大小。

      编辑:

      我错了。 /opt/local/var/macports/software/* 包含从中提取安装的 tarbells,因此大小会更小。

      如果你做 du -sh /opt/local,它应该列出所有东西的大小,但列表中可能有一些非 macports 包。

      port contents installed 命令将显示 macports 已安装的所有内容的目录。

      【讨论】:

      • 略微修改版本以查看按大小排序的项目:du -sk /opt/local/var/macports/software/*|排序 -n
      【解决方案3】:

      这是一个小 bash 函数,它将接受任何有效的 macports 查询

      function port_size {
          size=0
          pkg_size=0
          for pkg in $(port $@ | tail -n +2 | awk '{ print $1 }')
          do
              pkg_size=$(port contents $pkg \
                  | sed -r 's/^[[:space:]]*(.*)[[:space:]]*$/\1/g;s/ /\\ /g' \
                  | tail -n +2 | xargs du | cut -f1 | paste -sd '+' | bc)
              size=$(( $size + $pkg_size ))
              printf "%10d %s\n" $pkg_size $pkg
          done
          printf "%10d %s\n" $size "Total Size (KB)"
      }
      

      我只使用 GNU 版本的 sed 和 awk 对其进行了测试,但无论如何它都应该可以工作。

      port_size installed   # will print out all installed packages and their size
      
      port_size installed gcc*    # will print out all packages matching gcc* wildcard
      

      同样,任何有效的 macports 查询都可以工作(包括 installed inactiveoutdated

      【讨论】:

      • 但是 OS X 不附带 GNU sed,并且 BSD sed 不支持 -r 选项。无论如何,这里有一个单行代码,它会告诉你单个端口的大小(以 KB 为单位)(我以 guile 为例):port contents --size --units B guile | awk '{total += $1}; END{ printf("%0.2f KB\n", total/1024) }'
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      相关资源
      最近更新 更多