如何在命令行中从PPA /源列出软件包?


Answers:


37

查找以/var/lib/apt/lists/结尾的相关文件Packages,然后执行以下命令:

# example for deb http://security.ubuntu.com/ubuntu natty-security multiverse
awk '$1 == "Package:" { print $2 }' /var/lib/apt/lists/security*multiverse*Packages

顺便说一句,我extras.ubuntu.com_ubuntu_dists_natty_main_binary-i386_Packages是空的。

编辑

您还可以解析apt-cache输出。该脚本列出了所有包含服务器和仓库信息的软件包:

#!/bin/bash

apt-cache policy $(dpkg -l | awk 'NR >= 6 { print $2 }') |
  awk '/^[^ ]/    { split($1, a, ":"); pkg = a[1] }
    nextline == 1 { nextline = 0; printf("%-40s %-50s %s\n", pkg, $2, $3) }
    /\*\*\*/      { nextline = 1 }'

方便地对输出进行排序,您可以获得所需的信息。


不错,我从没想过要实际解析文件,我一直在寻找解析的输出的好方法apt-cache policy '.*'。这些软件包文件是从中检索的http://extras.ubuntu.com/ubuntu/dists/natty/main/binary-amd64/Packages.*可以使用gunzip或进行解压缩bunzip2
Lekensteyn

@Lekensteyn:我添加了apt-cache输出解析信息
enzotib

1
总是喜欢一个不错的awk单线答案。谢谢!
TML

8

我只是直接在服务器端检查,就像这样:

$ curl -s http://extras.ubuntu.com/ubuntu/dists/maverick/main/binary-i386/Packages.gz |
  gzip -d | grep Package
Package: news
Package: suspended-sentence

2

我为此编写了一个糟糕的脚本:

#!/bin/bash
clear
##array aufbauen
declare -a repoList=()
for i in $(ls /var/lib/apt/lists/ | grep _Packages)
do
    #echo $i
    repoList=("${repoList[@]}" "$i")
done

repoAnzahl=${#repoList[@]}
echo "Anzahl der Repos: " $repoAnzahl

for ((i=0;$i<$repoAnzahl;i++))
do
    if [[ "${repoList[$i]}" =~ "archive.ubuntu" ]]
    then
    rname=${repoList[$i]##*archive.ubuntu}
    echo "$i RepoName: " "${rname%%_binary*}"
    elif [[ "${repoList[$i]}" =~ "ubuntu" ]]
    then
    echo "$i RepoName: " "${repoList[$i]%%_ubuntu*}"
    else
    echo "$i RepoName: " "${repoList[$i]%%_dist*}"
    fi
done

read -p "Gib die RepoNummer ein: " repoNummer

packages=()
for i in $(cat /var/lib/apt/lists/${repoList[$repoNummer]} | grep Package)
do
    if ! [[ "$i" =~ "Package" ]]
    then
    packages=("${packages[@]}" "$i")
    fi
done

paketAnzahl=${#packages[@]}
echo "Anzahl der pakete: " $paketAnzahl

function listPackages () {
    for ((i=0;$i<$paketAnzahl;i++))
    do
    echo ${packages[$i]}
    done
}

if test $paketAnzahl -gt 20
then
    listPackages | less
else
    listPackages
fi

echo "Anzahl der Pakete: " $paketAnzahl
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.