How to find files in a Debian system not installed or created by dpkg?

I've installed some things manually in the past and would like to weed out all related files. So, I need a way to automatically find all the files (in /usr, for example) that are not included in any of the packages currently installed on the Debian system. However, I would also need to filter out the files that are created during package installation (by dpkg post-install scripts and similar things).


Solution 1:

Use the cruft package:

cruft is a program to look over the system for anything that shouldn't be there, but is; or for anything that should be there, but isn't.

Solution 2:

You could try something like this:

dpkg -L --list-all-package-files | grep "^/usr" > dpkg-files.dat   **(don't know the dpkg option "--list-all-package-files", read mand dpkg)**
find /usr -type f -o -type l > all-usr-files.dat
sort dpkg-files.dat all-usr-files.dat | uniq -c | grep " 1 "

This way you will get all files that are in /usr but not any package file. As a first shot this could help you.