list of installed packages without using apt?

Robert Heller heller at deepsoft.com
Mon Nov 27 23:43:23 UTC 2017


At Mon, 27 Nov 2017 18:14:53 -0500 "Ubuntu user technical support,  not for general discussions" <ubuntu-users at lists.ubuntu.com> wrote:

> 
> On 2017-11-27 17:18, Stuart McGraw wrote:
> > Is there some way of getting output similar to 'apt list --installed'
> > without using apt?  Specifically I want a list of installed packages,
> > their version numbers, and whether they were installed at my request
> > or as a dependency.  dpkg-query provides the first two items and I
> > think apt-mark the last, but the problem is combining them.
> > 
> > I dont want to use apt because: 1) I am using in a shell script and
> > apt prints an annoying warning, 2) The warning recommends against
> > using apt in scripts :-)  I want to use basic low-level commands
> > and not large complex things like apt or aptitude.
> 
> 1) Get rid of (most) warnings by throwing them away:
> $ command-that-generates-a-warning 2> /dev/null
> $
> The "2>" takes the secondary output stream -- "STDERR" -- and throws it 
> away.
> Note, of course, that this is dangerous if there's even a medium chance 
> you care about error messages from the command you're executing.
> 
> 2) Apt, etc., are pretty much front-ends against files in 
> /var/lib/apt/lists/ .  (Anyone who knows better, please correct me -- 
> it's been a while since I've dug into this.)  And if you really want to 
> get into it, feel free to roll your own scripts against those files.  
> But there simply aren't "low-level commands" that deal with those files 
> -- at least, not ones without the word "apt" in them. ;-)

There is a lower level command (that does not even mess with the files in 
/var/lib/apt/lists/) -- dpkg, and its friend dpkg-query.  These commands can 
also be useful.

And since the files in /var/lib/apt/lists/ are *text* files, they can be 
dealth with using grep and various other commands, like awk or perl or python 
or tcl.

> 
> $.02,
> 
> -Ken
> 

-- 
Robert Heller             -- 978-544-6933
Deepwoods Software        -- Custom Software Services
http://www.deepsoft.com/  -- Linux Administration Services
heller at deepsoft.com       -- Webhosting Services
                                                                                                                          




More information about the ubuntu-users mailing list