50

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.

1

4 Answers 4

43

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.

3
  • 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, 2011 at 7:53
  • @Lekensteyn: I added apt-cache output parsing information
    – enzotib
    May 18, 2011 at 8:02
  • 1
    Always love a nice awk one-liner answer. Thanks!
    – TML
    Jan 11, 2015 at 18:25
10

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
2

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
0

Something like this Python script should find all packages installed on your machine from that site (see this answer for the script that shows all non-Ubuntu packages):

#!/usr/bin/env python3
#
# This lists all packages from extras.ubuntu.com
#
# If you receive an import error, you may need to install python-apt first with e.g.
# sudo apt install python-apt
# but this is often not necessary

import apt


cache = apt.Cache()
package_count = 0

for package in cache:
    if (
        cache[package.name].is_installed
        and package.candidate.origins[0].site == "extras.ubuntu.com"
    ):
        package_origin = package.candidate.origins[0]
        print(
            package.name,
            # See https://apt-team.pages.debian.net/python-apt/library/apt.package.html#apt.package.Origin
            # for further details on the meanings of the below
            package_origin.origin,  # The Origin, as set in the Release file
            package_origin.archive,  # The archive (eg. Ubuntu release name)
            package_origin.component,  # The component (eg. main/universe)
            package_origin.site,  # The hostname of the site.
            # package_origin.label,  # The Label, as set in the Release file
            # package_origin.trusted,  # Origin trusted (Release file signed by key in apt keyring)
        )
        package_count += 1

print(package_count, "packages total")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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