Ubuntu dpkg-query can be used to find package name given a file name, its full path or partial name. Note that it does not follow symlinks when querying. Here are some scenarios you can use dpkg-query (or dpkg) to find package name from file name.
Fine packages based filename full or partial match
Either using filename or it full path
$ dpkg-query -S apache2.conf apache2: /etc/apache2/apache2.conf $ dpkg-query -S /etc/apache2/apache2.conf apache2: /etc/apache2/apache2.conf $ dpkg-query -S 2.conf apache2: /etc/apache2/apache2.conf upstart: /etc/init/tty2.conf
Find packages using filename wildcard match
$ dpkg-query -S awstats*conf awstats: /etc/awstats/awstats.conf.local awstats: /usr/share/doc/awstats/html/awstats_config.html awstats: /usr/share/doc/awstats/examples/awstats_configure.pl awstats: /usr/share/doc/awstats/examples/apache.conf awstats: /usr/share/awstats/icon/mime/conf.png awstats: /etc/awstats/awstats.conf
Find packages having files in a directory
To list packages which have something in apache mods-available folder
$ dpkg-query -S /etc/apache2/mods-available/ apache2, libapache2-mod-php5, libapache2-mod-python, libapache2-mod-svn: /etc/apache2/mods-available
dpkg-query and symlinks
dpkg-query can not follow symlink. So you should do that manually. e.g. To find package name for /usr/bin/mail
$ ls -l /usr/bin/mail lrwxrwxrwx 1 root root 22 Sep 3 18:14 /usr/bin/mail -> /etc/alternatives/mail ls -l /etc/alternatives/mail lrwxrwxrwx 1 root root 23 Sep 3 18:14 /etc/alternatives/mail -> /usr/bin/mail.mailutils $ dpkg-query -S /usr/bin/mail.mailutils mailutils: /usr/bin/mail.mailutils