Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know there's a which command, that echoes the full name of a binary (e.g. which sh). However, I'm fairly sure there's a command that echoes the package that provides a particular binary. Is there such a command? If so, what is it? I'd like to be able to run this:

commandName ls

and get

coreutils

for example.

share|improve this question

2 Answers 2

up vote 10 down vote accepted

I guess you are looking for the dpkg -S command (also see frequently used options for dpkg).

share|improve this answer
1  
Thank you! dpkg -S `which COMMANDHERE` worked for me. –  Delan Azabani May 30 '10 at 7:47
    
Gentoo: qfile <name> –  Sergei May 20 at 13:24

If you want to find files in a package that you haven't installed, use apt-file

apt-get install -y apt-file
apt-file update

Then, to find something:

apt-file search /usr/bin/file

or

apt-find search file

Where "file" is the name of whatever you're searching for.

If you don't feel like going through this on every debian system, you can use this script:

#!/bin/bash
which apt-get >/dev/null || { echo apt-get not found >&2; exit 1; }
which apt-file >/dev/null || { apt-get install -y apt-file;  apt-file update; }
unset i; IFS=$'\x0a'; select i in $( apt-file search "/$@" ); do 
    test -n "$i" || break; apt-get install "${i%% *}"; done

I just whipped that up then, but it seems to work well.

Note: "dpkg -S" only finds things that you've already installed.

share|improve this answer

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.