我很好奇是否有一种脚本友好的方法来计算apt list --upgradeable
.这会产生一个很好的输出,每行只有一个升级候选,非常易于解析。但是,apt
还警告:
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
所以我觉得我应该用venerable来apt-get
代替。不幸的是,它的输出看起来像这样:
apt-get -s --no-download dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
dbus libdbus-1-3
The following packages will be upgraded:
bash gcc-8-base gpgv libedit2 libgcc1 libprocps7 libpsl5 libselinux1 libsemanage-common libsemanage1 libsepol1 libsqlite3-0 libstdc++6 perl-base
procps publicsuffix rsyslog twigpilot-core
18 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
...
这是很难解析的。所以我希望有某种方式来获得apt-get
更新来打印更简洁的列表apt
。
答案1
我不经常使用 Ubuntu,但是这个怎么样:
$ apt-get -s --no-download dist-upgrade -V | grep '=>' | awk '{print$1}'
它每行打印一个包。如中所述man apt-get
:
-V, --verbose-versions
Show full versions for upgraded and installed packages. Configuration Item: APT::Get::Show-Versions.
答案2
是apt-show-versions -u
您要找的吗?从其联机帮助页:
-u
,--upgradeable
仅打印可升级包
在文本文件中列出所有可升级的软件包,并以列格式显示它们:
apt-show-versions -u | column -t > debupdlist-$(date '+%Y%m%d').txt
列出可升级包的名称:
apt-show-versions -u | cut -d: -f1