列出所有添加到我的系统的 PPA 软件源。

如何列出我系统中添加的所有ppa存储库,并将其保存到一个.txt文件中,这样我就不需要花时间在为新安装搜索ppa上,我只需在我的.txt文件中选择一个ppa行并附加到命令sudo add-apt-repository?还有其他方法可以做到这一点,而无需手动提供gpg密钥吗?
3个回答

对于那些只想检查已安装的PPA而不实际进行任何自动操作的人,你可以执行以下操作:
$ apt-cache policy

在我的系统中,这是它展示的一部分:
% apt-cache policy
Package files:
 100 /var/lib/dpkg/status
     release a=now
 500 http: ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu/ precise/main Translation-en
 500 http: ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu/ precise/main i386 Packages
     release v=12.04,o=LP-PPA-ubuntu-toolchain-r-test,a=precise,n=precise,l=Toolchain test builds,c=main
     origin ppa.launchpad.net
 500 http: ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu/ precise/main amd64 Packages
     release v=12.04,o=LP-PPA-ubuntu-toolchain-r-test,a=precise,n=precise,l=Toolchain test builds,c=main
     origin ppa.launchpad.net
 500 http: ppa.launchpad.net/rael-gc/scudcloud/ubuntu/ precise/main Translation-en
 500 http: ppa.launchpad.net/rael-gc/scudcloud/ubuntu/ precise/main i386 Packages
     release v=12.04,o=LP-PPA-rael-gc-scudcloud,a=precise,n=precise,l=ScudCloud - Linux client for Slack,c=main
     origin ppa.launchpad.net
...

引用自这里

[apt-cache policy]检索与每个存储库资源相关联的优先级。通过它的输出,您可以推断出所有可用的存储库和PPA的列表。

来源:http://ask.xmodulo.com/list-installed-repositories-ppas-ubuntu.html

5这个很简单明了,但是输出结果也包括了Ubuntu的基本软件源。如果你要这样做的话,不如直接使用你提供的链接中的完整命令:apt-cache policy | grep http | awk '{print $2 $3}' | sort -u。这样输出结果更有条理,更容易阅读。 - pjd
1注意:只有在运行“apt-get update”之后,“apt-cache policy”才会显示存储库。如果您刚刚使用“add-apt-repository”添加了一个存储库,则在运行“apt-get update”之前,它不会出现在“apt-cache policy”中。 - wisbucky

从{{link1:如何在命令行中获取所有存储库和PPA的列表以便安装脚本?}}

答案的一部分似乎有您要找的内容:

#! /bin/sh 
# listppa Script to get all the PPA installed on a system ready to share for reininstall
for APT in `find /etc/apt/ -name \*.list`; do
    grep -o "^deb http://ppa.launchpad.net/[a-z0-9\-]\+/[a-z0-9\-]\+" $APT | while read ENTRY ; do
        USER=`echo $ENTRY | cut -d/ -f4`
        PPA=`echo $ENTRY | cut -d/ -f5`
        echo sudo apt-add-repository ppa:$USER/$PPA
    done
done

将此保存为listppa.sh

listppa.sh > installppa.sh

这将创建一个脚本,您可以将其备份到某个地方,然后通过简单执行以下命令在全新安装上添加您的PPA:
installppa.sh

我的答案获取到的信息,在如何通过命令行获得所有存储库和PPA的列表,并转成安装脚本?中。

ppa:用户/仓库格式列出PPAs:

grep -E '^deb\s' /etc/apt/sources.list /etc/apt/sources.list.d/*.list |\
  cut -f2- -d: |\
  cut -f2 -d' ' |\
  sed -re 's#http://ppa\.launchpad\.net/([^/]+)/([^/]+)(.*?)$#ppa:\1/\2#g' |\
  grep '^ppa:'

列出所有包括PPA的仓库,格式为ppa:USER/REPO
只需删除最后一个grep(不要忘记在sed命令之后的上一行中删除|\)。
请参考我在其他问题中的答案,其中包含完整的脚本,您可以保存和使用,包括生成安装脚本。