Linux 使用 dpkg 查询包名时遇到 no path found matching pattern 的解决方法

15 篇文章 0 订阅

一般包名时会出现如下错误:

$ 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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lylhw13_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值