Find files not installed by RPM package manager

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.

Per, the following command is a solid baseline for what you need:

comm -13 <(rpm -qla | sort) <(find / -type f | sort)

Customize further by filtering the find command to directories of interest (either specifying the list of directories instead of / (e.g. /{usr,bin}) or excluding folders like /proc, /dev, /home, and /tmp.

As far as I'm aware, this is not possible with some kind of dedicated command, only via a little scripting. TL;DR - see the links at the bottom. And for rpm-based systems or other binary-based package managers this doesn't make much sense. Such package managers are usually state-based machines intended to keep track of the things that they install themselves, and not to know everything that users sneak onto the system "behind the back" of the package manager.

Where would you draw the line for files that are not owned by rpm files? What about temporary files ( think /tmp and /var/tmp ) or caches ( think /var/cache ) or files created by a user ( /home or /srv or other user-defined mountpoints ).

For source-based distros it might make sense to offer that functionality if the use case limits them to FHS directories used by "system" packages like /usr, /bin, /lib and similar, as opposed to e.g. /usr/local or /opt for 3rd party software.

See the following similar questions for scriptlets to do what you asked for:

  • How do I list all the files not owned by any package in a RPM-based system?
  • Mailing list thread: Clever way to find ALL files not owned by RPM?