Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

apt policy / listing packages from repo

52 views
Skip to first unread message

Gareth Evans

unread,
Aug 10, 2023, 5:50:07 AM8/10/23
to
There seems to be no mention of

apt policy

in either man apt or apt --help.

I was looking for a way to list packages installed from a particular repo and/or sub-repo or whatever it's called (eg. main, non-free).

Does anyone know of a way to do this, with apt policy or otherwise?

Thanks,
Gareth

David Wright

unread,
Aug 10, 2023, 10:40:06 AM8/10/23
to
On Thu 10 Aug 2023 at 10:46:27 (+0100), Gareth Evans wrote:
> There seems to be no mention of
>
> apt policy
>
> in either man apt or apt --help.

As man apt says:

"Much like apt itself, its manpage is intended as an end user
interface and as such only mentions the most used commands and
options partly to not duplicate information in multiple places
and partly to avoid overwhelming readers with a cornucopia of
options and details."

> I was looking for a way to list packages installed from a particular repo and/or sub-repo or whatever it's called (eg. main, non-free).
>
> Does anyone know of a way to do this, with apt policy or otherwise?

What I do in this situation is to type "apt" and press TAB twice.
Look at the resulting list of commands and check the man page for
the most likely looking, in this case apt-cache.

An alternative method of course is to type apt policy into any
search engine. This will typically tell you not only how to invoke
the command, but also more about what it produces.

As for your listing, I've done this in the past with a script that
runs apt-cache dump, grepping the Package/Version/File lines,
concatenating and sorting them, then filtering that list against
the output of dpkg-query -W -f to include only installed packages.
This yields a list like:

Package: acl Version: 2.2.53-10 File: /var/lib/apt/lists/deb.debian.org_debian_dists_bullseye_main_binary-amd64_Packages
Package: adduser Version: 3.118 File: /var/lib/apt/lists/deb.debian.org_debian_dists_bullseye_main_binary-amd64_Packages
[ … … ]
Package: xtoolwait Version: 1.3-6.2 File: /var/lib/dpkg/status
[ … … ]
Package: yt-dlp Version: 2023.03.04-1~bpo11+1 File: /var/lib/dpkg/status

which you can grep for particular subsets, though I'm usually more
interested in grep -v for packages originating from elsewhere,
like xtoolwait (squeeze) and yt-dlp (backports) there.

There may well be better ways.

Cheers,
David.

Sven Joachim

unread,
Aug 10, 2023, 2:00:07 PM8/10/23
to
On 2023-08-10 09:30 -0500, David Wright wrote:

>> I was looking for a way to list packages installed from a particular
>> repo and/or sub-repo or whatever it's called (eg. main, non-free).
>>
>> Does anyone know of a way to do this, with apt policy or otherwise?
>
> What I do in this situation is to type "apt" and press TAB twice.
> Look at the resulting list of commands and check the man page for
> the most likely looking, in this case apt-cache.
>
> An alternative method of course is to type apt policy into any
> search engine. This will typically tell you not only how to invoke
> the command, but also more about what it produces.
>
> As for your listing, I've done this in the past with a script that
> runs apt-cache dump, grepping the Package/Version/File lines,
> concatenating and sorting them, then filtering that list against
> the output of dpkg-query -W -f to include only installed packages.
> This yields a list like:
>
> Package: acl Version: 2.2.53-10 File: /var/lib/apt/lists/deb.debian.org_debian_dists_bullseye_main_binary-amd64_Packages
> Package: adduser Version: 3.118 File: /var/lib/apt/lists/deb.debian.org_debian_dists_bullseye_main_binary-amd64_Packages
> [ … … ]
> Package: xtoolwait Version: 1.3-6.2 File: /var/lib/dpkg/status
> [ … … ]
> Package: yt-dlp Version: 2023.03.04-1~bpo11+1 File: /var/lib/dpkg/status
>
> which you can grep for particular subsets, though I'm usually more
> interested in grep -v for packages originating from elsewhere,
> like xtoolwait (squeeze) and yt-dlp (backports) there.
>
> There may well be better ways.

I would probably use "apt list" with a search pattern described in
apt-patterns(7), e.g. the following command lists all installed packages
from non-free:

$ apt list '~i ~snon-free/'

Lots of interesting possibilities one can toy with. :-)

Cheers,
Sven

Gareth Evans

unread,
Aug 11, 2023, 12:10:06 AM8/11/23
to
I will look into both approaches - my thanks to you and David.

G
0 new messages