This guide is meant to help you identify a package that owns/provides a specific file on your Ubuntu system. All commands on this article have been tested on Ubuntu 18.04 and Ubuntu 16.04 Desktop and Server edition.
Sometimes it is necessary to know a package that added files in your system, this is usually critical for monitoring and security purposes, e.g prevent rootkits and any form of intrusion into your Linux server.
Below is a list of commands that come in handy for this task.
dpkg is a Debian package management tool used to install, remove, upgrade, and manage Debian packages. You can use dpkg package management tool to identify a package that provides a file. The options to use are:
-S, -- search: These are used to search for a filename from installed packages.
As an example, let's try to identify a package which provides /etc/updatedb.conf file.
# dpkg -S /etc/updatedb.conf mlocate: /etc/updatedb.conf
As seen, the file was written to the filesystem by mlocate package.
You can also do the same for a binary file, e.g
# dpkg -S /bin/sync coreutils: /bin/sync
If you don't know the absolute path of a command, you can use
which command to locate it on the fly.
# dpkg -S `which ping` iputils-ping: /bin/ping
# dpkg -S $(which ping) iputils-ping: /bin/ping
Apt-file is a Debian command line tool that you can use for searching files in packages for the APT package management system. If you try to execute the command when not installed, it should ask you to install it.
# apt-file search vim The program 'apt-file' is currently not installed. You can install it by typing: apt install apt-file
The system-wide cache is empty by default. Run the following command as root user to update the cache.
# apt-file update
# apt-file search <file>
E.g. To find a package that created the file /etc/nginx/nginx.conf, use the command:
# apt-file search /etc/nginx/nginx.conf nginx-common: /etc/nginx/nginx.conf
From the output, it can be seen that the file was created by the installation of the
Using Ubuntu Packages Search Web interface
The third method is to use Ubuntu Packages Search web interface accessible on ubuntu packages page/ . Enter keyword and click on the search box.
Read Also :
- How to Upgrade Individual Packages in Ubuntu/CentOS
- How to Show Installed Package Size on Ubuntu/Debian
- How to Remove Orphaned Packages on Ubuntu
- How to Install Specific Version of Package using apt-get
The two commands apt-file and dpkg are sufficient to locate a file from a package on Ubuntu and all Debian based Linux distributions. It can help you find a package to re-install if it is broken from a file or track unknown files on your file system.