暗无天日

=============>DarkSun的个人博客

查找某个文件属于哪个package的方法

https://www.garron.me/en/linux/find-which-package-library-belongs.html学到的

Debian/Ubuntu

我们需要借助 apt-file 来实现

sudo apt-get install apt-file -y

然后更新数据库

apt-file update

然后搜索

apt-file search ${file}

Archlinux

若只需要在已经安装的包内查询,则可以直接使用pacman

pacman -Qo ${file}
/usr/bin/nc 属于 gnu-netcat 0.7.1-6

若需要查询所有数据库中的包,则可以使用pacmang中的 -F 选项

# 更新package databases
sudo pacman -Fy
# 搜索文件
pacman -Fs ${file}
:: Synchronizing package databases...
 core is up to date
 extra is up to date
 community is up to date
 multilib is up to date
 archlinuxcn is up to date
extra/bash-completion 2.8-1
    usr/share/bash-completion/completions/nc
extra/gnu-netcat 0.7.1-7
    usr/bin/nc
community/openbsd-netcat 1.190_2-1
    usr/bin/nc

或者也可以使用 pkgfile

sudo pacman -S pkgfile --noconfirm

更新数据库信息

sudo pkgfile --update
:: Updating 5 repos...
  extra is up to date
  community is up to date
  multilib is up to date
  core is up to date
  archlinuxcn is up to date

使用pkgfile查询

pkgfile ${file}
extra/bash-completion
extra/gnu-netcat
community/openbsd-netcat

Redhat,Fedora,Centos

在已安装的包中检查执行

rpm -qf $(which ${file})
nmap-ncat-6.40-13.el7.x86_64

或者,在所有包中检查,执行

yum provides */${file}
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
1:bash-completion-extras-2.1-11.el7.noarch : Additional programmable completions
                                           : for Bash
Repo        : epel
Matched from:
Filename    : /usr/share/bash-completion/completions/nc



euca2ools-2.1.4-1.el7.centos.noarch : Eucalyptus/AWS-compatible command line
                                    : tools
Repo        : extras
Matched from:
Filename    : /usr/lib/python2.7/site-packages/euca2ools/nc



kde-runtime-4.10.5-11.el7.i686 : KDE Runtime
Repo        : os
Matched from:
Filename    : /usr/share/locale/l10n/nc



kde-runtime-4.10.5-11.el7.x86_64 : KDE Runtime
Repo        : os
Matched from:
Filename    : /usr/share/locale/l10n/nc



kf5-kdelibs4support-5.33.0-1.el7.x86_64 : KDE Frameworks 5 Tier 4 module with
                                        : porting aid from KDELibs 4
Repo        : epel
Matched from:
Filename    : /usr/share/kf5/locale/countries/nc



2:nmap-ncat-6.40-13.el7.x86_64 : Nmap's Netcat replacement
Repo        : os
Matched from:
Filename    : /usr/bin/nc



rngom-javadoc-201103-0.8.20120119svn.el7.noarch : Javadoc for rngom
Repo        : os
Matched from:
Filename    : /usr/share/javadoc/rngom/org/kohsuke/rngom/nc



2:nmap-ncat-6.40-13.el7.x86_64 : Nmap's Netcat replacement
Repo        : @os
Matched from:
Filename    : /usr/bin/nc