list of installed packages without using apt?
Tom H
tomh0665 at gmail.com
Tue Nov 28 13:02:04 UTC 2017
On Mon, Nov 27, 2017 at 10:30 PM, Xen <list at xenhideout.nl> wrote:
> Stuart McGraw schreef op 27-11-2017 23:18:
>>
>> 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.
>
> The problem is more apt being annoying than apt being bad.
>
> If you wanted to combine dpkg and apt-mark you would get something like:
>
> dpkg -l | grep "^ii" | awk {'print $2'} | while read name; do
> # now process version string
> version=${name#*-}
> name=${name%-*-*}
> apt-mark showmanual | grep -Fx "$name" && manual=yes || manual=
> done
You can combine "grep "^ii" | awk {'print $2'}" into "awk '/^ii/ {print $2}'".
But this is slow and only lists the package names.
You have to use an apt-related tool because dpkg-related tools don't
keep track of automatically-installed packages.
To list installed packages, their version numbers, and whether they
were installed automatically or not, you can use (in two steps to
avoid the slowness above but without an indication of manual/automatic
installation)
dpkg-query -W -f '${version} ${package}\n' $(apt-mark showmanual)
dpkg-query -W -f '${version} ${package}\n' $(apt-mark showauto)
aptitude isn't large and complex. You can use
aptitude search -F "%p %v# %M" ~i
which lists all installed packages, with the lines of those installed
automatically appended with an "A".
More information about the ubuntu-users
mailing list