31

I installed many packages from many PPAs on my system. I want to list all the installed packages which are installed from launchpad PPAs, not repositories.

Is this possible through command-line?

4

6 Answers 6

30

The following command returns the package name and its ppa (if installed from a ppa):

apt-cache policy $(dpkg --get-selections | grep -v deinstall$ | awk '{ print $1 }') | perl -e '@a = <>; $a=join("", @a); $a =~ s/\n(\S)/\n\n$1/g;  @packages = split("\n\n", $a); foreach $p (@packages) {print "$1: $2\n" if $p =~ /^(.*?):.*?500 http:\/\/ppa\.launchpad\.net\/(.*?)\s/s}'

Details:

  • dpkg --get-selections gives only the installed packages after grep -v deinstall$
  • awk '{ print $1 }' returns only the package name
  • perl -e '@a = <>; $a=join("", @a)' concatenates all the lines returned by apt-cache policy
  • $a =~ s/\n(\S)/\n\n$1/g; adds a newline between each package section
  • @packages = split("\n\n", $a); is a perl array containing all the packages infos, one package per item.
  • foreach $p (@packages) {print "$1: $2\n" if $p =~ /^(.*?):.*?500 http:\/\/ppa\.launchpad\.net\/(.*?)\s/s} is a loop where the package and the ppa are printed if a ppa with prio 500 is found in the policy.
1
  • Short answer/code, looong time for execution. Apr 13, 2014 at 15:00
13
4
  • 1
    Another Cool Capability of aptitude +1
    – Ravexina
    May 1, 2017 at 19:43
  • @user.dz On my ubuntu, aptitude says : E: Match pattern ends unexpectedly (expected ')').
    – SebMa
    Feb 10, 2020 at 16:51
  • @SebMa , I have just tried it in the online LXD container (Ubuntu 18.04.4 LTS) from linuxcontainers.org/lxd/try-it , it is working fine. Which shell you are using? and please confirm that you are using the same shell string limiters, as in 'string' .
    – user.dz
    Feb 10, 2020 at 17:05
  • 1
    @user.dz My mistake, I had an aptitude shell function which has a bug. Your command works on my system now. Thanks a lot :)
    – SebMa
    Feb 10, 2020 at 17:27
5

The source of an installed package can be checked using apt-cache, for example

$ apt-cache policy oracle-java7-installer

oracle-java7-installer:
  Installed: 7u51-0~webupd8~7
  Candidate: 7u51-0~webupd8~7
  Version table:
 *** 7u51-0~webupd8~7 0
        500 http://ppa.launchpad.net/webupd8team/java/ubuntu/ precise/main i386 Packages
        100 /var/lib/dpkg/status

The output of apt-cache policy <package_name> contains the source.

One can use the following script to obtain the list of packages installed from PPAs.

#!/bin/bash
echo "List of packages which are not installed from Ubuntu repository"
for i in `dpkg -l | grep "^ii" | awk '{print $2}'`
do
    j=`apt-cache policy "$i" | grep "ppa.launchpad.net"` 
    if [ $? -eq 0 ]; then
        echo "$i"
        #echo "$i $j"
    fi
done
5
  • 1
    It doesn’t work if you selected a different mirror. For instance I have gir1.2-syncmenu-0.1 500 http://ubuntu.univ-nantes.fr/ubuntu/ saucy/main amd64 Packages Apr 13, 2014 at 12:20
  • In this case google-chrome-stable is not installed from a PPA; it has just a separate repository. Apr 13, 2014 at 13:53
  • 1
    Ok, I saw that. But you came with a really bad example which can make novice users to think that if a package is not from Ubuntu repositories, then the package is from a PPA. The OP's question is about PPAs. Apr 13, 2014 at 14:27
  • @RaduRădeanu I got your points and Edited my post. you are absolutely correct.
    – sourav c.
    Apr 13, 2014 at 14:49
  • Better now, even if there is a problem with the time for execution which is realy looong. Apr 13, 2014 at 15:05
3

In accordance with this answer and this post, you can get a list of all packages from all the PPAs installed on your system using the following bash code:

for APT in $(find /etc/apt/ -name \*.list); do
  grep -o "^deb http://ppa.launchpad.net/[a-z0-9\-]\+/[a-z0-9\-]\+" $APT | while read ENTRY ; do
    USER=$(echo $ENTRY | cut -d/ -f4)
    PPA=$(echo $ENTRY | cut -d/ -f5)
    awk '$1 == "Package:" { if (a[$2]++ == 0) print $2; }' /var/lib/apt/lists/*$USER*$PPA*Packages
    done
done

And in accordance with this answer, you can get a list of all installed packages in your system using:

dpkg --get-selections | grep -v deinstall | cut -f1

Now, let's join these two ideas to get a list of all the packages which are installed from PPAs:

(for APT in $(find /etc/apt/ -name \*.list); do
  grep -o "^deb http://ppa.launchpad.net/[a-z0-9\-]\+/[a-z0-9\-]\+" $APT | while read ENTRY ; do
    USER=$(echo $ENTRY | cut -d/ -f4)
    PPA=$(echo $ENTRY | cut -d/ -f5)
    awk '$1 == "Package:" { if (a[$2]++ == 0) print $2; }' /var/lib/apt/lists/*$USER*$PPA*Packages
    done
done; dpkg --get-selections | grep -v deinstall | cut -f1) | sort | awk 'dup[$0]++ == 1'
3

Install synaptic. You can then browse packages by "origin" or even any other custom filter.

0

I wanted to know how many packages I had from each ppa, so I slightly modified Sylvain's awesome answer:

apt-cache policy $(dpkg --get-selections | grep -v deinstall$ | awk '{ print $1 }') \
| perl -e '@a = <>; $a=join("", @a); $a =~ s/\n(\S)/\n\n$1/g;  @packages = split("\n\n", $a); foreach $p (@packages) {printf "%-40s %s\n", $2, $1 if $p =~ /^(.*?):.*?500 http:\/\/ppa\.launchpad\.net\/(.*?)\s/s}' \
| sort \
| uniq -c -w 40

by printing ppa first and using only first 40 characters to count & deduplicate with uniq, I can get this kind of output:

  5 alexlarsson/flatpak/ubuntu               flatpak
147 bleedingedge/focal-bleed/ubuntu          bzip2
  1 justinabrahms/ttf-cascadia-code/ubuntu   ttf-cascadia-code
 44 libreoffice/ppa/ubuntu                   fonts-opensymbol
 71 savoury1/backports/ubuntu                bash
 41 savoury1/multimedia/ubuntu               dav1d
  8 strukturag/libheif/ubuntu                aom-tools
 12 ubuntugis/ubuntugis-unstable/ubuntu      gdal-bin

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .