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.

How would I go about writing a script to get the same list of installed software as reported by the Ubuntu Software Center?

Every reference I can find mentions either dpkg -l or rpm -qa (or some variant thereof), but these typically include every single last package and library and what-not, and you end up with a list of 1000+ entries.

The Ubuntu Software Center app however shows a much of concise (and human-friendly) list--currently 67 items on my Ubuntu box. This is the sort of list I'm interested in. Can anyone point me to a script that can obtain something similar? Preferably something that can run on other distributions, but I'll take whatever I can get.

Thanks.

share|improve this question

migrated from serverfault.com Apr 7 '11 at 16:59

This question came from our site for system and network administrators.

5 Answers 5

In Python, you can get the list of installed packages this way:

import apt
packages = apt.Cache()
packages.open()
installed_packages = [i.name for i in packages if i.is_installed]

If you want to know additional info about the packages, the process is a bit more involved. See the documentation for Python's apt module for all the information that's available. Additionally, you can look through the Software Center's source to find out what they do.

You won't get this info merely by looking at some file somewhere or running a simple command. You're going to need to do some scripting.

EDIT: I believe that Software Center gets its list of packages to show from those packages that ship .desktop files. It might be more complicated than that, but you can easily filter the list to those packages that are installed and have a .desktop file. This example continues my previous code:

import os
desktop_files = ['.'.join(i.split('.')[:-1]) for i in os.listdir('/usr/share/applications')]
installed_in_software_center = [i for i in installed_packages if i in desktop_files]
share|improve this answer

May still not be what you're looking for...

dpkg --get-selections

If not (I can't comment yet), run the following and let me know the number (just counts number of lines.

dpkg --get-selections | wc -l
share|improve this answer

You cat get the data from the logs in /var/log/apt. As the logs are rotated, most of them are compressed. First we combine the current log with the compressed ones, before we extract all the packages that was installed, but not automatically. This was just trial and error from my part, so it can probably be cleaned up a bit.

cd /var/log/apt   
sudo -s
cat history.log > allhistory
zcat history.log*gz >> allhistory.log
cat allhistory.log | grep Install | sed s/Install://g | tr ')' '\n' | grep -v automatic | sed s/,//g | sed s/:.*$//g | sort -u | grep -v "^$"
share|improve this answer
    
Theo--I'm still getting 1320 entries. Egil's script returns 1180. –  user13807 Apr 7 '11 at 17:57
    
Should cat history.log > allhistory be cat history.log > allhistory.log? –  user25656 Nov 11 '13 at 7:05

As far as I can tell, the Software Center filters based on the section the package is in. While it won't be exactly the same as the filter that the Software Center uses, you can do something similar by filtering out library packages:

dpkg --get-selections|grep -i -v "deinstall"|grep -v "lib"

The grep is to filter out the things that are either not installed or are generally hidden by the software center. You can add more things to filter out as needed - the "lib" string is a good indicator that it's not an end-user application.

share|improve this answer

Maybe APTonCD would help?

Its a tool that scans your APT-installed packages and build a list for you. You can then manually select/deselect the ones you want, save the list, and it can even download/use cache to save selected packages in a CD/folder (for an offline automatic install of currently installed apps)

It also has some filters like include dependencies, include old versions, etc..

APTonCD comes default in Mint 10, but since they share same Ubuntu repositories, you can install it via software manager.

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.