December 7, 2020 in Tutorial2 minutes
If you’re using rpm based Linux distribution, most likely you’re familiar with yum whatprovides
command. Using this command we can search which packages provides a specific file.
In Ubuntu or Debian-based Linux distribution we can also do similar action using dpkg and apt-file.
To get which packages provides a specific file we can use dpkg
command using -S
option. We only need to provide the file name that we want to search.
For example we can search which package providing lscpu
using command below.
$ dpkg -S lscpu
util-linux: /usr/share/man/man1/lscpu.1.gz
util-linux: /usr/share/bash-completion/completions/lscpu
util-linux: /usr/bin/lscpu
If apt-file is not installed on your system yet, you can use command below to install apt-file
sudo apt-get install apt-file
After installing apt-file we need to update apt-file database using command below
sudo apt-file update
To search the same file lscpu
using apt-file command below
$ apt-file search lscpu
fish-common: /usr/share/fish/completions/lscpu.fish
manpages-de: /usr/share/man/de/man1/lscpu.1.gz
manpages-fr-extra: /usr/share/man/fr/man1/lscpu.1.gz
manpages-pl: /usr/share/man/pl/man1/lscpu.1.gz
util-linux: /usr/bin/lscpu
util-linux: /usr/share/bash-completion/completions/lscpu
util-linux: /usr/share/man/man1/lscpu.1.gz
To search for a specific file we can use a full / absolute path of the file. For example
$ apt-file search /usr/bin/lscpu
util-linux: /usr/bin/lscpu
In this tutorial we learn how to use apt to do similar actions like yum whatprovides
does. Hope this is useful and see you next time. Happy Hacking!