13

I can list installed packages on my Fedora with:

dnf list installed

When searching for packages, I'd use something like:

dnf search terminal

dnf will proceed to list available packages similar to this:

tmux.x86_64 : A terminal multiplexer

i.e. "<package> : <summary>". I'd like to have a similar output of packages, but for installed packages. Search among installed packages is not necessary, as I can simply pipe the output into grep (or ripgrep), but an output like the one that results from a search is something I'd like to have.

2 Answers 2

7

The rpm database is already a collection of all your installed packages.

You can query the database directly with rpm and extract any available information using the --queryformat option without using any additional tools or loops:

rpm --query --all --queryformat '%{NAME}.%{ARCH}: %{SUMMARY}\n'

Adjust --queryformat to use whatever information rpm provides: http://ftp.rpm.org/api/4.4.2.2/queryformat.html

3
  • How to sort the result? Commented Apr 21, 2024 at 4:33
  • 1
    You can pipe the command to sort to get sorted results. Commented Apr 22, 2024 at 7:41
  • Nice command! How you install only a specific version of a Kernel installed on, say, Fedora? Commented May 14 at 6:44
1

Something like

for pkg in $(dnf list --installed) ; do
  rpm -q --queryformat '%{NAME} : %{SUMMARY}\n' ${pkg}
done

might do the trick (untested, since written on a phone).

The for ... do ... done loop is of course a bit over the top, but it does allow you to do some extra filtering if you want to, log things, surround them in proper HTML, whatever your heart desires

5
  • Right, I'm assuming a command purely reliant on dnf isn't possible? Commented Aug 3, 2022 at 1:31
  • 2
    Not that I'm aware of Commented Aug 3, 2022 at 1:32
  • Thanks, that explains a bit. For now I'm using dnf list --installed | cut -f1 -d' ' | xargs -I '{}' rpm -q --queryformat '{} : %{SUMMARY}\n' '{}' based on your suggestion. I'll see if someone else comes up with something insightful for a day or two before accepting. Commented Aug 3, 2022 at 1:45
  • 4
    Since rpm already has a database of all the installed packages, should be no need for additional tools or loops: rpm -qa --queryformat '%{NAME}.%{ARCH}: %{SUMMARY}' Commented Aug 3, 2022 at 1:58
  • @GracefulRestart thanks, please add an answer I can accept. Commented Aug 4, 2022 at 20:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.