Answers:
man apt-get
显示:
-s, --simulate, --just-print, --dry-run, --recon, --no-act
No action; perform a simulation of events that would occur based on
the current system state but do not actually change the system.
Locking will be disabled (Debug::NoLocking) so the system state
could change while apt-get is running. Simulations can also be
executed by non-root users which might not have read access to all
apt configuration distorting the simulation. A notice expressing
this warning is also shown by default for non-root users
(APT::Get::Show-User-Simulation-Note). Configuration Item:
APT::Get::Simulate.
因此,如果您这样做:
apt-get upgrade --dry-run
它将输出:
...
4 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
...
man 8 apt-get
并找到了该选项,但输出结果与有所不同apt
。
apt
它实际上是一个程序包装器apt-get
,这就是警告存在的原因。
apt
显示8 packages can be upgraded. Run 'apt list --upgradable' to see them.
,而您的答案显示4 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
apt
不会保证您输入该文本,甚至可能无法保证您输入该数字。 apt-get
但是对输出有严格的要求,因为其他软件(例如UI和守护程序)使用它以各种方式对其进行处理。因此,例如,您可以更改代码以接受apt-get
的输出,也可以| sed 's/to upgrade/packages can be upgraded/g'
(例如,并且可能在以后破坏代码)。
猜测您需要处理可用更新的数量,这是一个建议:
# With no option, returns two numbers, no CR nor LF
/usr/lib/update-notifier/apt-check
# With --human-readable, returns numbers, locale LANG text & CR/LF
/usr/lib/update-notifier/apt-check --human-readable
无需sudo
输出易于使用
更多选择:
> /usr/lib/update-notifier/apt-check --help
Usage: apt-check [options]
Options:
-h, --help show this help message and exit
-p, --package-names Show the packages that are going to be
installed/upgraded
--human-readable Show human readable output on stdout
--security-updates-unattended
Return the time in days when security updates are
installed unattended (0 means disabled)
motd
SSH登录时生成的确切内容吗?
apt
(高级包装工具)apt-get
与之不同。它们的设计与我所理解的不同。如果有人给了您想要的东西,也许养成使用该命令的习惯。