This is not documented as far as I can tell but a leading /
makes dpkg
treat the argument as a path and not a pattern. In other words, if you tell it to search for something that starts with /
, it assumes it should look for a file in one of the installed packages with that exact path.
You can confirm it easily enough with
$ dpkg -S nonmatching
dpkg-query: no path found matching pattern *nonmatching*
$ dpkg -S /nonmatching
dpkg-query: no path found matching pattern /nonmatching
Note that in the first case, with no /
, the error shows that it searched for *nomatching*
, while with the /
it searched for the exact path /nonmatching
. For example, it also fails to find /doc
despite the existence of directories like /usr/share/doc
:
$ dpkg -S /doc
dpkg-query: no path found matching pattern /doc
While I can't find any mention of this in the man page, I did confirm by checking the source. The following lines are from the searchfiles
function defined in querycmd.c
(dpkg 1.17.13)
if (!strchr("*[?/",*thisarg)) {
varbuf_reset(&vb);
varbuf_add_char(&vb, '*');
varbuf_add_str(&vb, thisarg);
varbuf_add_char(&vb, '*');
varbuf_end_str(&vb);
thisarg= vb.buf;
}
That will add *
around the argument passed unless that argument begins with a /
. So, that causes dpkg-query
to treat anything starting with /
as an absolute path and anything that doesn't as a pattern to be matched.