I'm on system running a (fairly recent-)Debian-based distribution.
I'd like to generate a plain list of all installed packages matching a certain pattern. I can do that by, running, say,
apt list --installed "linux-image-*" | cut -d/ -f1
but I get lines I don't care for, e.g.:
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Listing...
So maybe I'd better not use apt
. I can run dpkg-query like so:
dpkg-query --showformat='${Package}\n' --show "linux-image*"
but that's not limited to installed packages. I could use
dpkg-query --list "linux-image-*" | grep "ii"
but then I'd need to do a bunch of text processing, and who can trust those spaces, right?
So, bottom line: What's the right way to get the list of installed packages matching a pattern?
Note:
- Bonus points if it can be a proper regexp rather than just a shell glob.
- Having to parse the text seems like a less-than-ideal solution; if that's what you suggest, please argue why there isn't a better way.