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).
2 Answers
Use the cruft-ng
package:
cruft-ng 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.
-
1Note that as of 2022-10-07, cruft was removed from testing and may disappear from Debian. Feb 25 at 2:55
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.
-
I can't find any way to get -L to list more than one package at a time, but you can get the same effect from
grep -h "^/usr" /var/lib/dpkg/info/*.list > dpkg-files.dat
– DerfKFeb 21, 2011 at 16:04 -
-
@DerfK: You can get -l to list more than one package, for example like this:
dpkg -L `aptitude search ~i -F "%p"`
– KarolFeb 21, 2011 at 16:11 -
The problem with this approach is that there are more files or links in /usr than actually listed by dpkg. For example, /usr/bin/aptitude exists, probably created by some post-installation script, but it's not listed by dpkg. So, I guess what I want here is a list of files installed or created by installing any package (will change question).– KarolFeb 21, 2011 at 16:18
-
@Karol: Other sources of files could be diversions and alternatives. The output is in sentence form but you can see diversions with
dpkg-divert --list
as root (These are usually given a suffix). Alternatives are a bit harder, the file format in /var/lib/dpkg/alternatives/ is awkward andupdate-alternatives
tells me just about everything BUT the name of the link.find /usr -lname '/etc/alternatives/*'
is probably the easiest way to get these.– DerfKFeb 21, 2011 at 16:47