bash 获取依赖 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
#!/bin/bash
a=$(sudo apt install -s 2>/dev/null | grep Inst | awk '{ print }')
for i in $a; do
b=$(apt show $i 2>/dev/null | grep Installed-Size | awk '{ print }')
done
您可以使用 dpkg-query
而不是使用 apt
来提取有关脚本中的包的信息,正如评论中已经提到的那样,它具有稳定的界面。
例如,您可以获得 just 包的 Installed-Size
,每行一个,然后将数字与 awk
:[=19 相加=]
$ dpkg-query -Wf '${Installed-Size}\n' | awk '{ sum += [=10=] } END { print sum " KB" }'
4650121 KB
注意,Installed-Size
会给你:
an estimate of the total amount of disk space required to install the
named package. Actual installed size may vary based on block size,
file system properties, or actions taken by package maintainer
scripts.
The disk space is given as the integer value of the estimated
installed size in bytes, divided by 1024 and rounded up.
有关 dpkg-query
的更多信息:man dpkg-query
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
#!/bin/bash
a=$(sudo apt install -s 2>/dev/null | grep Inst | awk '{ print }')
for i in $a; do
b=$(apt show $i 2>/dev/null | grep Installed-Size | awk '{ print }')
done
您可以使用 dpkg-query
而不是使用 apt
来提取有关脚本中的包的信息,正如评论中已经提到的那样,它具有稳定的界面。
例如,您可以获得 just 包的 Installed-Size
,每行一个,然后将数字与 awk
:[=19 相加=]
$ dpkg-query -Wf '${Installed-Size}\n' | awk '{ sum += [=10=] } END { print sum " KB" }'
4650121 KB
注意,Installed-Size
会给你:
an estimate of the total amount of disk space required to install the named package. Actual installed size may vary based on block size, file system properties, or actions taken by package maintainer scripts.
The disk space is given as the integer value of the estimated installed size in bytes, divided by 1024 and rounded up.
有关 dpkg-query
的更多信息:man dpkg-query