list of installed packages without using apt?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

list of installed packages without using apt?

Stuart McGraw
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.


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: list of installed packages without using apt?

Ken D'Ambrosio
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

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: list of installed packages without using apt?

Robert Heller
At Mon, 27 Nov 2017 18:14:53 -0500 "Ubuntu user technical support,  not for general discussions" <[hidden email]> 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
[hidden email]       -- Webhosting Services
                                                                                                                         

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: list of installed packages without using apt?

Oliver Grawert
In reply to this post by Stuart McGraw
hi,
Am Montag, den 27.11.2017, 15:18 -0700 schrieb Stuart McGraw:

> 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 proper way would be:

dpkg -l | grep ^ii

installed debian packages store package info in /var/lib/dpkg/info/ ...
if you don't want to use dpkg-query or dpkg -l you could also do
something (slightly hackish) like:

ls /var/lib/dpkg/info/|grep .md5sums

to get the list of installed packages ... 


ciao
        oli
--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

signature.asc (188 bytes) Download Attachment
Xen
Reply | Threaded
Open this post in threaded view
|

Re: list of installed packages without using apt?

Xen
In reply to this post by Stuart McGraw
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

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: list of installed packages without using apt?

Thufir Hawat
In reply to this post by Stuart McGraw
On Mon, 27 Nov 2017 15:18:02 -0700, Stuart McGraw wrote:


> I dont want to use apt because: 1) I am using in a shell script and apt
> prints an annoying warning


Have you tried apt-cache?

I don't know how safe it is...just a suggestion.  I can't recall, but apt-
get and apt-cache don't display that warning, I *think*, when run in bash
scripts.


-Thufir


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: list of installed packages without using apt?

Tom H-4
In reply to this post by Xen
On Mon, Nov 27, 2017 at 10:30 PM, Xen <[hidden email]> 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".

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: list of installed packages without using apt?

Stuart McGraw
On 11/28/2017 06:02 AM, Tom H wrote:

> On Mon, Nov 27, 2017 at 10:30 PM, Xen <[hidden email]> 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".

I think the answer to my question, "is there any low-level command that
will give me installed package info and auto/manual status?" turns out
to be "no".

The options as I understand are:
1. Extract the info from /var/lib/apt/lists and /var/lib/dpkg/info
2. Combine the outputs of apt-mark and dpkg-query (or related  commands)
3. Get the info from aptitude or app

Seems like the best option for me is 2, a variation on Xen/TomH's ideas:
  (dpkg-query -W -f '${package} ${version}\n' $(apt-mark showauto)|sed -e 's/$/ A/'; \
  dpkg-query -W -f '${package} ${version}\n' $(apt-mark showmanual)|sed -e 's/$/ M/';) | sort

While I like Ubuntu so far, I have to say that package management seems
a bit of a hodge-podge.  Not really a criticism since everything seems to
work ok but takes a while to learn one's way around. :-)

Thanks very much for all the ideas!


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users