list of installed packages without using apt?

Ken D'Ambrosio ken at jots.org
Mon Nov 27 23:14:53 UTC 2017


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. ;-)

$.02,

-Ken




More information about the ubuntu-users mailing list