一般包名时会出现如下错误:
$ dpkg -S <file_name>
dpkg-query: no path found matching pattern <file_name>
可能原因是:文件名是一个符号链接
比如需要查询 nc 的包名称:
$ which nc
/usr/bin/nc
$ dpkg -S /usr/bin/nc
dpkg-query: no path found matching pattern /usr/bin/nc
其中 which nc 查询出来的是符号链接
解决办法:
方法1: 通过 ls 逐步找到对应的目标文件。
$ which nc
/usr/bin/nc
$ ll /usr/bin/nc
lrwxrwxrwx 1 root root 20 Aug 22 2020 /usr/bin/nc -> /etc/alternatives/nc*
$ ll /etc/alternatives/nc
lrwxrwxrwx 1 root root 15 Aug 22 2020 /etc/alternatives/nc -> /bin/nc.openbsd*
$ dpkg -S /bin/nc.openbsd
netcat-openbsd: /bin/nc.openbsd
方法2: 通过 readlink 找到目标文件
但是直接使用有时也是会出现问题,比如:
$ readlink -f $(which nc)
/usr/bin/nc.openbsd
$ dpkg -S /usr/bin/nc.openbsd
dpkg-query: no path found matching pattern /usr/bin/nc.openbsd
这是因为 /bin 是指向 /usr/bin/ 的符号链接。
$ ll /bin
lrwxrwxrwx 1 root root 7 Aug 28 2020 /bin -> usr/bin/
虽然有些文件是安装在于/bin 目录下,但是最终解析还是会解析到符号链接所指向的路径,即 /usr/bin 目录下。
因此,需要查询 /bin/nc.openbsd,而不是 /usr/bin/nc.openbsd
$ dpkg -S /bin/nc.openbsd
netcat-openbsd: /bin/nc.openbsd