0

I have found a file (say "badfile") in /usr/bin which do not seem to belong to any package installed on my system:

$ dpkg -S /usr/bin/badfile
dpkg-query: no path found matching pattern /usr/bin/badfile
$ apt-file search /usr/bin/badfile
# nothing is returned

I think I want to remove this file or move it to /usr/local/bin. This being said, presumably, there could be other such files. Is there a way to list all files in a certain repository (here, /usr/bin/) that the Debian apt package manager does not know about?

1
  • 2
    Just a note of caution if you are considering extending this to configuration files: you may come across files (/etc/ssh/sshd_config comes to mind) that aren't part of any dpkg filelist, but instead are created on-the-fly by a package's pre/post installation script. Commented Aug 17, 2016 at 0:49

1 Answer 1

5

You can pass multiple filenames to dpkg -S to report on all the files in one go

eg

dpkg -S /usr/bin/* > /dev/null

Now this isn't perfect; symbolic links don't get reported properly

eg

dpkg-query: no path found matching pattern /usr/bin/lzdiff

This also means things like pointers to alternatives will be reported badly because they're symlinks.

If you want to cut down on false positives we can use find:

find /usr/bin -type f -exec dpkg -S {} + > /dev/null

On my Debian Jessie machine this results in

dpkg-query: no path found matching pattern /usr/bin/flash-player-properties
2
  • Thanks! Just thought it'd check whether there was a more standard way. Note that, when doing this on large file collections, I got an error zsh: argument list too long: dpkg, so I ended up doing find /usr/bin -type f | xargs dpkg -S > /dev/null
    – a3nm
    Commented Aug 17, 2016 at 8:30
  • 1
    @a3nm Make that find /usr/bin -type f -exec dpkg -S {} + >/dev/null, otherwise this command breaks on file names containing spaces (as does dkpg -S $(…). It happens that Debian doesn't ship any files with names containing spaces in /usr/bin (there are some under /usr/share at least), but your system might have some. Commented Aug 17, 2016 at 21:40

You must log in to answer this question.

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