Is there a command that would get rid of files that are not connected to anything?
Sorry if this sounds stupid I"m just trying to clean up my Linux rig. Thanks for your help.
“connected” is a tricky word to interpret. Just because a file is not owned by a package (according to the package database) does not mean that it is not important.
That said, yes, you can query what package a file belongs to. The command is rpm -qf <path-to-file> (e.g. rpm -qf /etc/hosts). You would have to script that to find all the “unowned” files under a given directory.
Beware that “getting rid of unowned files” is very much a “shoot yourself in the foot” sort of operation and Linux will let you do that. ![]()
All that said, I have personally done such things in the past. I preferred to do it just before I did a major upgrade from one version of Fedora Linux to the next, on the theory that if I deleted some file that shouldn’t have been deleted, there would be at least a chance that it would be restored on the subsequent upgrade since that typically re-downloads and rewrites all the package files.
Good luck and don’t forget to make backups. ![]()
Thank you I’ll heed the warning!
Not sure if this will satisfy your needs but,
everytime you update the rpm’s are cached up so you can re install them quickly if needed you can clear it by
sudo dnf clean all
It dosent affect current programs, just frees up disk space.
Give a read to
and
If you have a question let us know ![]()
Thank you
That question is different from the title “Safely remove unused packages/dependencies”. For unused packages, you can run sudo dnf autoremove. It will remove any package that is marked as automatically installed but no longer has another package depend on it.
You can double check what’s going to be removed with:
dnf repoquery --unneeded
I usually just run the command and read the list when it asks for my confirmation. ![]()