Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 14 down vote accepted

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.

share|improve this answer
    
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-amd64/, those Packages.* files can be uncompressed using gunzip or bunzip2. –  Lekensteyn May 18 '11 at 7:53
    
@Lekensteyn: I added apt-cache output parsing information –  enzotib May 18 '11 at 8:02

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
share|improve this answer

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|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.