I'm contemplating writing a script that does this:

  • Goes through each file in /usr/lib
  • Does a dpkg -s search on each file.
  • Reports a list of "orphan" files not belonging to any .deb package.

The idea is that over time, I've installed a lot of make install software and I'd like to get a list of leftover files from manually installed software I've since deleted.

  • In the future, make sure everything you install outside the packaging system gets installed to /usr/local or /opt. Then you'll have a clear separation. – geirha Feb 29 '12 at 14:35
find /usr/lib -type f -exec dpkg -S {} + 2>&1 >/dev/null | sed -r 's/^[^/]+//'

I'll warn you now: it's slow.

| improve this answer | |
  • 3
    It's faster: find /usr/lib -type f -exec dpkg -S {} + | grep 'no path found' – αғsнιη Mar 24 '15 at 12:08
  • 1
    No disagreement there. 2012's Oli wasn't as good as 2015's. I've updated it so it only returns a list of files. – Oli Mar 24 '15 at 14:00

You can run the following command

join -t '' -v1 <(find /usr/lib | sort) \
               <(grep -h /usr/lib /var/lib/dpkg/info/*.list | sort -u)

that compare the list of files in /usr/lib with the list of files present in at least a file in /var/lib/dpkg/info/<NAME>.list (the files used by dpkg -S). The -v1 option would report files present in the first list but not in the second one.

On my machine this difference list gives more than 5000 hits, so I doubt it could be of any help.

| improve this answer | |
  • Works really fast for me. – user1202136 May 20 '14 at 15:12
sudo aptitude install cruft
man cruft
sudo addgroup cruft
sudo chmod g+rwx /var/spool/cruft
sudo chown root:cruft /var/spool/cruft
sudo addgroup $USER cruft
cruft -r cruftreport
sudo chown root:root /var/spool/cruft
less cruftreport
| improve this answer | |
  • 1
    I like the man cruft in there, but a tiny bit more explanation on cruft and why you recommend it would be nice! :P ;-) – Fabby Mar 24 '15 at 11:50
  • This will not work, more precise: (1) "chown: missing operand after ‘root:cruft’". Need to write: "sudo chown root:cruft /var/spool/cruft" instead (2) "sudo addgroup $USER cruft" will require closing/opening new shell (relogin). (3) Calling cruft will require "sudo cruft" if you want to inspect all dirs. – muenalan May 8 '17 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.