#!/bin/bash
# 用于检查系统中安装的软件包大小
# 用法:./check.sh | less
# 作者:azio7
pacman -Qi | awk '/^名字/ {name=$3} /^安装后大小/ {size=$3; unit=$4;
if (unit=="KiB") size*=1024; else if (unit=="MiB") size*=1024*1024;
else if (unit=="GiB") size*=1024*1024*1024; printf "%s %f\n",name,size}' |
sort -k2 -n |
awk '{
s=$2 + 0;
size=s;
unit="B";
if (s > 1024*1024*1024) {
size=s/1024;
size=size/1024;
size=size/1024;
unit="GiB";
} else if (s > 1024*1024) {
size=s/1024;
size=size/1024;
unit="MiB";
} else if (s > 1024) {
size=s/1024;
unit="KiB";
}
printf "%-40s %8.3f %s\n",$1,size,unit;
}'