简体   繁体   English

bash 获得 package 大小与依赖 apt

[英]bash get package size with dependencies apt

how can i get the total sum for all the packages in the loop?我怎样才能得到循环中所有包裹的总和?
I guess I must use bc but I'm clueless right now我想我必须使用 bc 但我现在一无所知

#!/bin/bash
a=$(sudo apt install $1 -s 2>/dev/null | grep Inst | awk '{ print $2 }') 
for i in $a; do
    b=$(apt show $i 2>/dev/null | grep Installed-Size | awk '{ print $2 }')  
done

instead of using apt to extract infos about packages in scripts, you can use dpkg-query , which has a stable interface, as already mentioned in the comments.您可以使用dpkg-query ,而不是使用apt在脚本中提取有关包的信息,它具有稳定的界面,正如评论中已经提到的。

for example you can get just the Installed-Size of the packages, one per line, an then sum the numbers with awk :例如,您可以获取软件包的Installed-Size ,每行一个,然后将数字与awk

$ dpkg-query -Wf '${Installed-Size}\n' | awk '{ sum += $0 } END { print sum " KB" }'
4650121 KB

note, Installed-Size will give you:请注意, Installed-Size将为您提供:

an estimate of the total amount of disk space required to install the named package.估计安装命名的 package 所需的磁盘空间总量。 Actual installed size may vary based on block size, file system properties, or actions taken by package maintainer scripts.实际安装大小可能因块大小、文件系统属性或 package 维护者脚本所采取的操作而异。

The disk space is given as the integer value of the estimated installed size in bytes, divided by 1024 and rounded up.磁盘空间以估计安装大小的 integer 值(以字节为单位)除以 1024 并向上取整给出。

for more infos about dpkg-query : man dpkg-query有关dpkg-query的更多信息: man dpkg-query

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM