19

In my system I have files that not belong to any package, they are mine or from compiled programs installed with make install. How can I find all files that do not belong to any package?

4 Answers 4

12

In /var/lib/dpkg/info are .list text files that list all the files contained in each package¹ installed through Debian's package manager.

Finding all files in the filesystem not matching any entry there can be achieved with something naïve like this:

find / -xdev -type f \( -exec grep -xq "{}" /var/lib/dpkg/info/*.list \; -or -print \)

This will obviously take a very long time as the whole filesystem will be scanned. If you use different partitions for system directories (such as /usr or /var), specify them after the initial /.

Warning: That does not include files created by package scripts. For instance:

  • /etc/hosts.allow is not listed anywhere but it might come from libwrap0 that possibly created it, if that file didn't exist at time of the package installation.
  • Many files are compiled during installation, for example .pyc files (compiled Python libraries), .elc files (compiled Emacs Lisp librarires), etc.
2
  • 2
    error find: argument list too long
    – naught101
    Commented Aug 16, 2018 at 4:14
  • @naught101 That suggests there are a gazillion files matching /var/lib/dpkg/info/*.list — above query would need to be rewritten under some other principle. Commented Aug 20, 2018 at 19:32
11

A more efficient version of @Patrice's solution, using a shell with support for process substitution (bash, AT&T ksh, zsh):

(
  export LC_ALL=C
  comm -23 <(find / -xdev -type f | sort) \
           <(sort -u /var/lib/dpkg/info/*.list)
)

Like Patrice's solution, it assumes no file path contains newline characters.

1
  • 1
    Would using the locate database be faster than running find? locate \* | grep -v "^/home/" - also has the benefit of looking in /boot/ and other system partitions.
    – naught101
    Commented Jun 6, 2018 at 3:45
11

Since you tagged your question with debian the obvious choice not mentioned yet is to use cruft-ng if you don't require any flexibility or cruft if you don't want to search through the whole system/locatedb.

0

You can also use process substitution & grep & find. Note that the grep is used twice to filter only relevant paths from /var/lib/dpkg/info to save few seconds if you are looking for files in a certain directory.

dir="/lib/x86_64-linux-gnu"
find "$dir" -type f \
| grep -v -x -F -f \
    <(find '/var/lib/dpkg/info' -name '*.list' -print0 \
       | xargs -0 grep -h -F "^$dir" \
       | sort -u)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .