是打開sources.list
和/或的唯一方法嗎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