Fedora – Find files not installed by RPM package manager

dnffedorarpmyum

Is there some way to find out all the files on a given system that weren't installed via RPM? I understand that I can brute force this myself using something like rpmquery -f in a script that loops through all files in the file system, however I was wondering if there is some standard way to do this for RPM based systems (specifically Fedora, which I use at home). Since this for Fedora, it is fine to use yum or dnf to figure this out.

If there is no standard way to do it, does anyone know of some pre-existing scripts to do this? I don't want to re-invent the wheel if I don't need to.

P.S. There is another question similar to this, but it is about Gentoo and Portage, so it isn't totally relevant.

Best Answer

a bit late to the party, but hopefully someone will find this useful:

find /usr/ -exec /bin/sh -c "rpm -qf {} &> /dev/null || echo {}" \;

This command crawls over the file system, and runs rpm -qf on it. rpm -qf prints the corresponding package for a file, and luckily has a return value of 0 if it finds one and 1 otherwise.

If you're brave, you can tie the output to | xargs rm -f, but personally I wouldn't be so brave. Turns out there's a lot of stuff in /usr that's not really owned by anything.