我如何获取已启用的 repos?

我如何获取已启用的 repos?

是否只有一种方法可以打开sources.listand/or sources.list.d?我想要类似这样的内容:

apt list enabled_repos

答案1

这取决于您想要什么输出格式。

apt-cache policy显示当前源及其应用的优先级:

~ apt-cache policy
Package files:
 100 /var/lib/dpkg/status
     release a=now
 500 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial/main i386 Packages
     release v=16.04,o=LP-PPA-webupd8team-java,a=xenial,n=xenial,l=Oracle Java (JDK) 8 / 9 Installer PPA,c=main,b=i386
     origin ppa.launchpad.net
 500 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial/main amd64 Packages
     release v=16.04,o=LP-PPA-webupd8team-java,a=xenial,n=xenial,l=Oracle Java (JDK) 8 / 9 Installer PPA,c=main,b=amd64
     origin ppa.launchpad.net
 500 http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu xenial/main i386 Packages
     release v=16.04,o=LP-PPA-ubuntu-wine,a=xenial,n=xenial,l=Wine Team PPA,c=main,b=i386
     origin ppa.launchpad.net
 500 http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu xenial/main amd64 Packages
     release v=16.04,o=LP-PPA-ubuntu-wine,a=xenial,n=xenial,l=Wine Team PPA,c=main,b=amd64
     origin ppa.launchpad.net
 500 http://ppa.launchpad.net/jonathonf/vim/ubuntu xenial/main i386 Packages
     release v=16.04,o=LP-PPA-jonathonf-vim,a=xenial,n=xenial,l=Vim,c=main,b=i386
     origin ppa.launchpad.net
 500 http://ppa.launchpad.net/jonathonf/vim/ubuntu xenial/main amd64 Packages
     release v=16.04,o=LP-PPA-jonathonf-vim,a=xenial,n=xenial,l=Vim,c=main,b=amd64
....

此处的信息可用于其他 apt 配置,例如 aptpreferences或 的配置unattended-upgrades

您还可以使用Python API

#! /usr/bin/env python3
import aptsources.sourceslist
sources = sourcesList.SourcesList()
for source in sources:
    if not (source.disabled or source.invalid):
        print(source.line.strip())

输出如下:

deb http://jp.archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial main restricted
deb http://jp.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
deb http://jp.archive.ubuntu.com/ubuntu/ xenial universe
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial universe
deb http://jp.archive.ubuntu.com/ubuntu/ xenial-updates universe
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-updates universe
deb http://jp.archive.ubuntu.com/ubuntu/ xenial multiverse
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://jp.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
deb http://jp.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu xenial-security main restricted
deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://security.ubuntu.com/ubuntu xenial-security universe
deb-src http://security.ubuntu.com/ubuntu xenial-security universe

相关内容