How to list configured APT repositories

List configured APT data sources for binary packages using apt-cache utility.

Notice that this solution will not list repositories for source packages.

First approach

The simplest approach is to use apt-cache utility to print package repositories.

$ apt-cache policy | awk '/http/ { printf "%s %s\n",$2,$3 }' | sort | uniq
http://ftp.us.debian.org/debian/ wheezy-backports/contrib
http://ftp.us.debian.org/debian/ wheezy-backports/main
http://ftp.us.debian.org/debian/ wheezy-backports/non-free
http://ftp.us.debian.org/debian/ wheezy/contrib
http://ftp.us.debian.org/debian/ wheezy/main
http://ftp.us.debian.org/debian/ wheezy/non-free
http://security.debian.org/ wheezy/updates/contrib
http://security.debian.org/ wheezy/updates/main
http://security.debian.org/ wheezy/updates/non-free

Second approach

Modify it a bit to pretty print the parsed data.

$ printf "%-60s %s\n" "URI" "Suite and section"; apt-cache policy | awk '/http/ { printf "%-60s %s\n",$2,$3 }' | sort | uniq | sed -e "s|\(.*\)\/|\1 |"
URI                                                          Suite and section
http://ftp.us.debian.org/debian/                             wheezy-backports contrib
http://ftp.us.debian.org/debian/                             wheezy-backports main
http://ftp.us.debian.org/debian/                             wheezy-backports non-free
http://ftp.us.debian.org/debian/                             wheezy contrib
http://ftp.us.debian.org/debian/                             wheezy main
http://ftp.us.debian.org/debian/                             wheezy non-free
http://security.debian.org/                                  wheezy/updates contrib
http://security.debian.org/                                  wheezy/updates main
http://security.debian.org/                                  wheezy/updates non-free

You can quickly extend it to print out the priorities of each source.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.

Gdansk, Poland https://sleeplessbeastie.eu