首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将"apt-get更新“显示为”apt update“的确切输出

将"apt-get更新“显示为”apt update“的确切输出
EN

Ask Ubuntu用户
提问于 2019-03-25 06:26:59
回答 3查看 2.6K关注 0票数 8

我正在学习高级打包工具的CLI接口。从apt(8)的输出中,当它的stdout不是终端时,它不适合“脚本期望稳定的编程接口”,所以我来看看apt-get(8)

apt updateapt-get update的一个不同之处在于,在更新了所有缓存之后,后者缺少了最后一行:

代码语言:javascript
运行
复制
8 packages can be upgraded. Run 'apt list --upgradable' to see them.

我想知道如何用apt-get(8)显示这一行。

EN

回答 3

Ask Ubuntu用户

发布于 2019-03-25 06:34:30

man apt-get显示:

代码语言:javascript
运行
复制
   -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

它将输出:

代码语言:javascript
运行
复制
...
4 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
...
票数 9
EN

Ask Ubuntu用户

发布于 2019-03-25 06:59:08

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

代码语言:javascript
运行
复制
# 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

没必要这么做

输出很容易使用。

更多选择:

代码语言:javascript
运行
复制
> /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)
票数 4
EN

Ask Ubuntu用户

发布于 2019-03-25 06:30:39

来自man 8 apt

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

然后我浏览了/usr/share/doc/apt/examples/configure-index.gz (使用zcat(1)显示文本内容)并注意到这个选项:

代码语言:javascript
运行
复制
apt::cmd::show-update-stats

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

代码语言:javascript
运行
复制
# apt-get -o apt::cmd::show-update-stats=true update

测试是在做异能和仿生的工作。

票数 2
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1128447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档