Re: apt policy / listing packages from repo
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.
Reply to: