如果我在我的 Ubuntu18(Ubuntu 18.04.4 LTS)测试机上运行以下命令,我会看到以下定义的存储库:
root@ubuntu18:/root# cat /etc/apt/sources.list | grep -v '#'
deb http://archive.ubuntu.com/ubuntu bionic main restricted
deb http://archive.ubuntu.com/ubuntu bionic-updates main restricted
deb http://archive.ubuntu.com/ubuntu bionic universe
deb http://archive.ubuntu.com/ubuntu bionic-updates universe
deb http://archive.ubuntu.com/ubuntu bionic multiverse
deb http://archive.ubuntu.com/ubuntu bionic-updates multiverse
deb http://archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu bionic-security main restricted
deb http://archive.ubuntu.com/ubuntu bionic-security universe
deb http://archive.ubuntu.com/ubuntu bionic-security multiverse
跑步apt 列表--可升级显示我有可用的更新,但是我想知道每个更新来自哪个存储库,或者运行命令来遍历每个定义的存储库并显示相应的更新列表。
答案1
正如您所知,您可以使用以下命令列出可升级的软件包:
apt list --upgradable
...例如在我的系统上显示:
$ apt list --upgradable
Listing... Done
gdb/lunar 13.1-2ubuntu2 amd64 [upgradable from: 12.1-0ubuntu1~22.04]
google-chrome-stable/stable 119.0.6045.105-1 amd64 [upgradable from: 118.0.5993.117-1]
libpeas-1.0-0/lunar 1.36.0-1 amd64 [upgradable from: 1.32.0-1]
libpython3-dev/lunar 3.11.2-1 amd64 [upgradable from: 3.10.6-1~22.04]
libsndfile1/lunar-updates,lunar-security 1.2.0-1ubuntu0.1 amd64 [upgradable from: 1.2.0-1]
可以使用以下命令查看有关各个软件包(包括其存储库)的更多信息:
apt policy package-name
... 喜欢:
$ apt policy gdb
gdb:
Installed: 12.1-0ubuntu1~22.04
Candidate: 13.1-2ubuntu2
Version table:
13.1-2ubuntu2 500
500 http://archive.ubuntu.com/ubuntu lunar/main amd64 Packages
*** 12.1-0ubuntu1~22.04 100
100 /var/lib/dpkg/status
因此,您可以修剪前者的输出并将其传递给后者,以使用类似以下方式实现自动化:
apt list --upgradable |& awk -F'/' '/\//{print $1}' | xargs apt policy
...在我的系统上,它看起来像这样:
$ apt list --upgradable |& awk -F'/' '/\//{print $1}' | xargs apt policy
gdb:
Installed: 12.1-0ubuntu1~22.04
Candidate: 13.1-2ubuntu2
Version table:
13.1-2ubuntu2 500
500 http://archive.ubuntu.com/ubuntu lunar/main amd64 Packages
*** 12.1-0ubuntu1~22.04 100
100 /var/lib/dpkg/status
google-chrome-stable:
Installed: 118.0.5993.117-1
Candidate: 119.0.6045.105-1
Version table:
119.0.6045.105-1 500
500 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages
*** 118.0.5993.117-1 100
100 /var/lib/dpkg/status
libpeas-1.0-0:
Installed: 1.32.0-1
Candidate: 1.36.0-1
Version table:
1.36.0-1 500
500 http://archive.ubuntu.com/ubuntu lunar/main amd64 Packages
*** 1.32.0-1 100
100 /var/lib/dpkg/status
libpython3-dev:
Installed: 3.10.6-1~22.04
Candidate: 3.11.2-1
Version table:
3.11.2-1 500
500 http://archive.ubuntu.com/ubuntu lunar/main amd64 Packages
*** 3.10.6-1~22.04 100
100 /var/lib/dpkg/status
libsndfile1:
Installed: 1.2.0-1
Candidate: 1.2.0-1ubuntu0.1
Version table:
1.2.0-1ubuntu0.1 500
500 http://archive.ubuntu.com/ubuntu lunar-updates/main amd64 Packages
500 http://archive.ubuntu.com/ubuntu lunar-security/main amd64 Packages
*** 1.2.0-1 500
500 http://archive.ubuntu.com/ubuntu lunar/main amd64 Packages
100 /var/lib/dpkg/status