我很惊讶最简单但最有效的方法,将所有已启用的二进制软件源与它们所指定的文件一起获取,竟然还没有被发布出来。
grep -r --include '*.list' '^deb ' /etc/apt/sources.list /etc/apt/sources.list.d/
从所有处理过的文件中,这将打印以
deb
开头的每一行。这不包括被注释的行,也不包括启用源代码存储库的
deb-src
行。
它实际上只搜索将由
apt
解析的所有
*.list
文件,但不搜索用于备份或具有非法名称的其他
*.list.save
文件。
如果你想要一个更短的输出,但可能只在99.9%的情况下是正确的,这可能会搜索太多的文件(包括所有的`/etc/apt/sources.list*`文件和目录,而不仅仅是`/etc/apt/sources.list`和`/etc/apt/sources.list.d/*`),你也可以使用以下方法:
grep -r --include '*.list' '^deb ' /etc/apt/sources.list*
除非有不应该存在的文件,否则输出将是相同的。
我的机器上的一个示例输出是这样的:
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily main restricted
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates main restricted
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily universe
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates universe
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily multiverse
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates multiverse
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-backports main restricted universe multiverse
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security main restricted
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security universe
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security multiverse
/etc/apt/sources.list:deb http://archive.canonical.com/ubuntu wily partner
/etc/apt/sources.list.d/maarten-fonville-ubuntu-ppa-wily.list:deb http://ppa.launchpad.net/maarten-fonville/ppa/ubuntu wily main
/etc/apt/sources.list.d/webupd8team-ubuntu-tor-browser-wily.list:deb http://ppa.launchpad.net/webupd8team/tor-browser/ubuntu wily main
/etc/apt/sources.list.d/fossfreedom-ubuntu-indicator-sysmonitor-wily.list:deb http://ppa.launchpad.net/fossfreedom/indicator-sysmonitor/ubuntu wily main
/etc/apt/sources.list.d/getdeb.list:deb http://archive.getdeb.net/ubuntu wily-getdeb apps
如果你想要更漂亮的输出,我们可以通过
sed
进行处理:
grep -r --include '*.list' '^deb ' /etc/apt/ | sed -re 's/^\/etc\/apt\/sources\.list((\.d\/)?|(:)?)//' -e 's/(.*\.list):/\[\1\] /' -e 's/deb http:\/\/ppa.launchpad.net\/(.*?)\/ubuntu .*/ppa:\1/'
我们将会看到这个:
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily main restricted
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates main restricted
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily universe
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates universe
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily multiverse
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates multiverse
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-backports main restricted universe multiverse
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security main restricted
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security universe
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security multiverse
deb http://archive.canonical.com/ubuntu wily partner
[maarten-fonville-ubuntu-ppa-wily.list] ppa:maarten-fonville/ppa
[webupd8team-ubuntu-tor-browser-wily.list] ppa:webupd8team/tor-browser
[fossfreedom-ubuntu-indicator-sysmonitor-wily.list] ppa:fossfreedom/indicator-sysmonitor
[getdeb.list] deb http://archive.getdeb.net/ubuntu wily-getdeb apps
egrep -v '^#|^ *$' /etc/apt/sources.list /etc/apt/sources.list.d/*
这个命令是用来删除被注释掉和空行的内容。 - user25656grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/*
中,grep
后面的^
是什么意思? - user25656cat /etc/apt/sources.list /etc/apt/sources.list.d/*
会更简单一些吧。 - jbo5112^[^#]
。 - Zelphir Kaltstahlgrep ^
而不是cat
真的很令人困惑。 - Konrad Rudolph