Bug#1076155: dpkg-query --search does not use partial pathnames as pattern

Vincent Lefevre <[email protected]>
Newsgroups gmane.linux.debian.devel.dpkg.bugs
Message-ID <20250507094333.GA1485114__12016.2805121922$1746611127$gmane$org@qaa.vinc17.org>
On 2024-07-11 12:32:44 -0400, js wrote:
> dpkg-query does not use a partial pathname as a pattern to search.
> 
> Example:
>   => which exiftool
>    /bin/exiftool
>   => dpkg-query --search `which exiftool`
>    dpkg-query: no path found matching pattern /bin/exiftool
>   => dlocate `which exiftool`
>    libimage-exiftool-perl: /usr/bin/exiftool
>   => dpkg-query --search /usr/bin/exiftool
>    libimage-exiftool-perl: /usr/bin/exiftool
>   => /bin/ls -lt /usr/bin/exiftool /bin/exiftool
>    -rwxr-xr-x 1 root root 320936 Feb  2 19:43 /bin/exiftool
>    -rwxr-xr-x 1 root root 320936 Feb  2 19:43 /usr/bin/exiftool

This seems to be the intended behavior. In the dpkg-query(1) man page:

       -S, --search filename-search-pattern...
[...]
           If the first character in the filename-search-pattern is
           none of ‘*[?/’ then it will be considered a substring match
           and will be implicitly surrounded by ‘*’ (as in
           *filename-search-pattern*).

Since your searches start with "/", you are requesting an exact match.

Using realpath solves the issue:

$ dpkg-query --search $(realpath /bin/exiftool)
libimage-exiftool-perl: /usr/bin/exiftool

You could write a small script that does what you want.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.