How to list packages from a ppa/source in command line?

23,160

Solution 1

Find the relevant file in /var/lib/apt/lists/ ending in Packages, and perform this command:

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

By the way, my extras.ubuntu.com_ubuntu_dists_natty_main_binary-i386_Packages is empty.

EDIT

You could also parse apt-cache output. This script lists all packages with server and repo information:

#!/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 }'

Sorting conveniently the output you can get the infos you're looking for.

Solution 2

I would just check directly on the server-side, like that:

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

Solution 3

I made a terrible script for that:

#!/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
Share:
23,160

Related videos on Youtube

Ubuntuser
Author by

Ubuntuser

Linux &amp; Ubuntu Enthusiast. Author for "Getting Started with Ubuntu".

Updated on September 18, 2022

Comments

  • Ubuntuser
    Ubuntuser over 1 year

    I want to list all the files from a source, say extras.ubuntu.com from the command line. What is the command for that?

    dpkg --list lists all files or just the filename.

  • Lekensteyn
    Lekensteyn almost 13 years
    Nice, I've never thought of actually parsing the files, I was looking for a good way to parse the output of apt-cache policy '.*'. These packages file is retrieved from http://extras.ubuntu.com/ubuntu/dists/natty/main/binary-amd6‌​4/, those Packages.* files can be uncompressed using gunzip or bunzip2.
  • enzotib
    enzotib almost 13 years
    @Lekensteyn: I added apt-cache output parsing information
  • TML
    TML over 9 years
    Always love a nice awk one-liner answer. Thanks!