使“ apt-get update”将确切的输出显示为“ apt update”。


8

我正在学习Advanced Packaging Tool的CLI界面。从apt(8)stdout不是终端的输出来看,它不适合“期望稳定编程接口的脚本”,因此我来看看apt-get(8)

apt update和之间的区别apt-get update是,在更新所有缓存后,后者缺少最后一行:

8 packages can be upgraded. Run 'apt list --upgradable' to see them.

我想知道如何使用来显示此确切行apt-get(8)


据我所知,apt(高级包装工具)apt-get与之不同。它们的设计与我所理解的不同。如果有人给了您想要的东西,也许养成使用该命令的习惯。
布伦登·麦克法林

Answers:


9

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
iBug

不同如何?我只是检查了我的系统,它是相同的。我认为这是相同的,因为apt它实际上是一个程序包装器apt-get,这就是警告存在的原因。
tu-Restate Monica-dor duh,

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.
iBug

1
是的,那是因为您有8个要升级到我有4个的升级。还是您指的是不同的文字?
tu-Restate Monica-dor duh,

4
是的,这正是警告的含义。 apt不会保证您输入该文本,甚至可能无法保证您输入该数字。 apt-get但是对输出有严格的要求,因为其他软件(例如UI和守护程序)使用它以各种方式对其进行处理。因此,例如,您可以更改代码以接受apt-get的输出,也可以| sed 's/to upgrade/packages can be upgraded/g'(例如,并且可能在以后破坏代码)。
tu-Restate Monica-dor duh,

4

猜测您需要处理可用更新的数量,这是一个建议:

# 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)

这是用于motdSSH登录时生成的确切内容吗?
iBug

是的,它看起来像是相同的输出,但是我不知道motd是怎么回事
cmak.fr 19-03-25

2

来自man 8 apt

...启用一些选项...

然后,我经历了/usr/share/doc/apt/examples/configure-index.gzzcat(1)用来显示文本内容)并注意到了这个选项:

apt::cmd::show-update-stats

因此,我制定了以下命令,该命令完全符合我的要求:

# apt-get -o apt::cmd::show-update-stats=true update

经测试可用于Xenial和Bionic。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.