January 20, 2009 Archives

20-01-2009 18:28

Listed installed packages in Debian

The other day I needed to list packages I have installed that were associated with MythTV on my MythTV box runing Ubuntu 8.04. So all using ssh and bash. I looked at the dpkg man pages was dispointed I could not find a switch that would only show installed packages. So with a bit googling I surprisingly could not find a quick one liner for this. So I set out to make my own.

To list packages with dpkg is simply:

dpkg -l <search sting> 

Easy enough. But that lists packages with all different status. So to narrow that down we pipe to grep and use a regex [regular expression] to show only lines that begin with 'ii', the status of installed.

dpkg -l "*myth*" | grep -e "^ii.*"

What we have done here is list all packages dpkg is aware of that contain "myth" in their names. Then we pipe that to grep and tell it to use the regex of "^ii.*" on it by using the grep switch of -e. ^ means the start of the line, ii means the literal characters, 'ii' and .* means anything after it.

For more info on regex, just do a handy search on your prefered search engine, there is lots of info out there on how to use this powerful tool.

Posted by DaveQB | Permanent Link | Categories: IT