Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Say, I'm given a filename like libasound.so.2. Is there a way to query the package manager to correlate the filename with its corresponding package?

I'm interested to get answers for any package manager, but my primary focus is on apt and yum.

share|improve this question
    

5 Answers 5

up vote 2 down vote accepted

Here's how to do this for the most common package managers (slightly adapted from here):

  1. Debian and its derivatives

    • Installed packages:

      dpkg -S /path/to/file
      

      or

      dlocate /path/to/file
      
    • All available packages

      Install apt-file and build its database:

      sudo apt-get install apt-file && apt-file update
      

      Then, search for all packages available in the distribution's repositories (installed or not) that provide the file of interest:

      apt-file search /path/to/file
      
  2. Red Hat/Fedora

    • Installed packages:

      rpm -qf /path/to/file
      
    • All available packages:

      yum whatprovides
      
  3. SUSE/openSUSE, all other RPM-based distributions

    rpm -qf /path/to/file
    
  4. Arch

    pacman -Qo /path/to/file
    
  5. Gentoo

    equery belongs /path/to/file
    
share|improve this answer
2  
With pacman, the q (quiet) option is also useful: pacman -Qikk "$(pacman -Qqo /path/to/file)" –  Amphiteót Jun 27 at 1:04

For the sake of completeness, this is on a yum based system

yum whatprovides /sbin/shutdown

or, just use rpm:

rpm -qf /sbin/shutdown
share|improve this answer
    
..or rpm -qf $(which shutdown) to find what package you have installed that is providing that command. –  Caleb Aug 3 '11 at 9:25

For apt, from the manual page for dpkg:

-S|--search <pattern> ...        Find package(s) owning file(s).

You have to give it the full path to the file.

For yum you should be able to query using rpm:

rpm -qf <path to file>

(but I don't have a yum/rpm system to check).

What might be helpful in general (if you know what to do in one or the other package manager): https://wiki.archlinux.org/index.php/Pacman_Rosetta

share|improve this answer

dpkg -S gives us this on a Ubuntu 10.04

dpkg -S /sbin/shutdown 
upstart: /sbin/shutdown

But on a Debian 5 box I get this

dpkg -S /sbin/shutdown 
sysvinit: /sbin/shutdown
share|improve this answer

Which installed package provides /sbin/shutdown on my system?

$ dpkg -S /sbin/shutdown
sysvinit: /sbin/shutdown

Which package in the distribution provides /sbin/shutdown? Install the apt-file package and run apt-file update if necessary, then

$ apt-file search /sbin/shutdown
molly-guard: /usr/sbin/shutdown
sysvinit: /sbin/shutdown
upstart: /sbin/shutdown

To download the source (if you're using the default init system SysVinit):

apt-get source sysvinit

This is probably not the place to configure desktop notifications though. Configuring the boot and shutdown process is typically done through scripts in /etc/init.d. Link a script in /etc/rc0.d to have it executed on shutdown and in /etc/rc6.d to have it executed before rebooting; see the policy manual for more information. Desktop notifications go through dbus.

share|improve this answer
    
+1 for the note on dbus –  Johan Aug 2 '11 at 8:09
    
Thanks for detailed explanation. What I meant was to report "System going down in NN minutes" messages that shutdown emits to user terminals via wall command. My initial idea was to make libnotify read wall messages by anyone and display them in desktop. But developers in Debian (Fedora too) felt that best way is for shutdown to call libnotify as they felt writing/reading utmp was archaic. –  Akilan Aug 2 '11 at 14:27
    
One can also use dlocate in place of dpkg -S. –  Faheem Mitha Jun 26 at 21:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.