When you run apt-get update, it keeps a list of everything in /var/lib/apt/lists/ inside the files that end with “_Packages”. So you can parse the files for lines that begin with the word “Package:” and “Version:” which will list the package/program name and its version. Then you can combine the two lines Package and Version with “paste” command, so that the package and its version are on the same line (which make it so its 1 line per package).

So after running apt-get update you get this output:

cat /var/lib/apt/lists/mirrors.kernel.org_debian_dists_wheezy_main_binary-amd64_Packages | egrep "^Package: |^Version: "| paste -s -d " \n"

Then you have sed to make it easier on the eyes, and sort to sort by package name:

cat /var/lib/apt/lists/mirrors.kernel.org_debian_dists_wheezy_main_binary-amd64_Packages | egrep "^Package: |^Version: "| paste -s -d " \n" | sed 's/Version:/-/;s/Package: //' | sort -k1

Now If you want good output about all of your repos check this out:

# first edit /etc/apt/sources.list
apt-get update
(cd /var/lib/apt/lists; rm -rf /tmp/pkglistcounts/; mkdir /tmp/pkglistcounts/ 2> /dev/null;
for i in *_Packages;do cat $i | egrep "^Package: |^Version: "| paste -s -d " \n" | sed 's/Version:/-/;s/Package: //' | sort -k1 > /tmp/pkglistcounts/$i; done;
cd /tmp/pkglistcounts/; wc -l *_Packages | sort -nk1; rm -rf /tmp/pkglistcounts/)

Output will be like this:

      3 apt.readynas.com_packages_readynasos_dists_6.2.2_updates_binary-amd64_Packages
      3 www.readynas.com_packages_readynasos_dists_6.2.2_updates_binary-amd64_Packages
    155 apt.readynas.com_packages_readynasos_dists_6.2.2_apps_binary-amd64_Packages
    155 www.readynas.com_packages_readynasos_dists_6.2.2_apps_binary-amd64_Packages
    673 apt.readynas.com_packages_readynasos_dists_6.2.2_main_binary-amd64_Packages
    673 www.readynas.com_packages_readynasos_dists_6.2.2_main_binary-amd64_Packages
   1560 security.debian.org_dists_wheezy_updates_main_binary-amd64_Packages
  35925 mirrors.kernel.org_debian_dists_wheezy_main_binary-amd64_Packages
  39147 total

 

Leave a Reply

Your email address will not be published. Required fields are marked *