Dnf: list packages that no other depends on?

I have been trying to find out how to list packages on my machine that are not dependents of other packages, as I’m looking to minimize the footprint of the OS (which I consider to include stuff I use). I have read through the dnf docs (more than once) and performed various searches to no avail. One would think there would be a dnf list --nodependents or similar command.

Is this possible (with dnf, yum or rpm)? If not, how would I go about suggesting that to the dnf developers?

Thanks for the help!!

C

1 Like

dnf repoquery --unneeded

This means that you can remove those package without breaking any dependency, not whether it’s unneeded for you.

Kind regards,

2 Likes

Thank you very much! Yes, --unneeded I think is a misnomer.
–nodependents would make more sense (to me, anyway)…

Please mark the answer as correct when you have a minute.

(And please feel free to file a bug against dnf: https://docs.fedoraproject.org/en-US/quick-docs/howto-file-a-bug/)

1 Like

Then again, maybe not… After reading the man page, it is not clear to me that this is listing ALL of the packages for which no others depend. It reads to me that those listed using --unneeded were once dependencies and are no longer, which is a good start, but I’m also (possibly?) interested in packages that may have been installed at any point which I do not use. As an example of a package I’d expect to see (although I don’t want to remove it) is libreoffice.

You are right. e.g. thunderbird is not listed, but can be removed without any problem. There is already a discussion in bugzilla item 1244777 about this. The old “package-cleanup --leaves” is not equivalent to the --unneeded option of dnf. I think only packages installed as dependency are shown.
For the moment, I can only propose a quick-and-dirty script making a package list and find whether this package is not needed by another one. The list is long, so use it at your own risk…

#!/bin/sh

showunused()
{
while read rpm
do
result=$(rpm -q --whatrequires "$rpm")
if test "${result:0:19}" = "no package requires"
then
echo $rpm
fi
done
}

rpm -qa --queryformat "%{NAME}\n" | sort >/tmp/packagelist
showunused </tmp/packagelist
1 Like

There’s a package called rpmreaper. It can display the leaf rpms much easier.

Thanks for the info! I’m definitely getting closer!! :slight_smile:

One tweak I made to the script was to add --unique to the sort command. I only need to see the package name once. :slight_smile:

The mention of the bugzilla item lead me to find the ‘leaves’ plug-in for dnf. Basically, all you have to do is
dnf install 'dnf-command(leaves)'
dnf leaves

However that gives different results from the script provided. As an example from my system, comparing the script (left) to leaves (right) using diff shows

1,2d0
< aalib-libs
< abattis-cantarell-fonts
13c11
< akonadi
---
> akregator
15c13
< alsa-lib
---
> alsa-firmware
(etc.)

So it’s not that only one is including packages that the other does not; each has their own idea of what “is not a dependent” means. It may have to do with leaves’ reciprocal logic (if A depends on B and B depends on A, both A and B will be listed by leaves if no other package is dependent on either), but that doesn’t account for the script’s listing of a package not listed by leaves…

I haven’t yet determined which I consider “better” for my purposes, but will post back once I do, and if there seems to be any logic as to why there are differences.

As an aside, I really don’t like the term “unused” in this context, and “leaf” is just as bad for different reasons. Is there any real reason to not use “no dependents” or “not a provider”?

And aside #2, I was pretty disappointed with the bugzilla comments. I really, really wish people would stop trying to protect me from myself! (Not just bugzilla posts or software, but with laws, too!) I’ll step off my soapbox now… :slight_smile:

Thanks to all for the help so far!

C

Sorry, I am stuck with your question and have to study the rpm system.
Example: boost-chrono : No package requires this rpm.
But: you cannot delete it, because of dependencies.
“yum remove boost-chrono” wants to remove up to the complete libreoffice.
So the script is definitively wrong.
A rpm has “capabilities”, and even if no package requires this rpm, it might require one of the capabilities in it… May be a capability can be provides by multiple packages???
So: let’s reduce the script to “a rpm can be deleted if it can be deleted” (not my idea, its mentioned elsewhere)

#!/bin/sh

showunused()
{
while read rpm
do
if rpm -e --test "$rpm" >/dev/null 2>/dev/null
then
echo $rpm
fi
done
}

rpm -qa  | sort | uniq >/tmp/packagelist
showunused </tmp/packagelist

In this case, the result of “dnf leaves” and the output of this script come close, but there are
differences left and right.
e.g. gwenview and gwenview-libs are in “dnf leaves” but only can be removed together so they are not in the script output.

Good luck!

1 Like

+1

Just because no other package requires a package, does not imply that no other package requires the various capabilities this package provides. The capabilities create the dependency tree. A package name may be used as a capability, but capabilities can be a lot more than that.

Worth looking at:

rpm -q --requires <package name>
rpm -q --provides <package name>
1 Like

Thanks.
Thanks the question of the original poster I learned a lot about RPMS. The essentials are under the hood. Deep respect for the package maintainers producing a working release every half a year.
The non-standard “dnf leaves” seems at the end the best way to get rpm’s which might be deleted.
My system has 3364 rpm’s and 845 leaves which might or might be not relevant, to be examined on individual base. And no libreoffice in the list. Probably, if you want to do major clean-ups, you can, with backup and rescue system at hand, try “dnf remove libreoffice*” , 482 Mbyte freed. But be prepared for sideeffects, may be Java program’s do not run anymore…
May be the only way to get a really clean and lean system is to save the user data and reinstall a minimal system with only terminal, and carefully add the packages you really need.
And there might be also a lot of stuff outside the RPM’s, I find e.g. 100Mbyte under ~/.config for whatever reasons…

Kind regards,

2 Likes

I’ve learned a lot, too!

My goal isn’t to reduce disk consumption (although I don’t like unnecessary use either). My primary goal is to reduce the time it takes to do a dnf upgrade. I recently realized that I didn’t need kernel-debug* packages, which should reduce upgrade times fairly substantially (as they have long-running scripts). Removing other updates that mean nothing to me would be good.

For the time being, I’ll use dnf leaves as a starting point, and use (sometimes uneducated :slight_smile:) judgement as to whether I really want a package or not.

I’m not sure I can mark any of these posts as “answers”, although all have helped getting to a semi-usable solution.

Thanks to ALL that contributed!!

C

1 Like