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
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 fromlibwrap0
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
-
@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. Aug 20, 2018 at 19:32
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.
-
1Would using the
locate
database be faster than runningfind
?locate \* | grep -v "^/home/"
- also has the benefit of looking in/boot/
and other system partitions. Jun 6, 2018 at 3:45
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.
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)