Finding out what package a command came from [duplicate]

Is there a generalised way to find out what package caused the installation of a command?


Solution 1:

Open a terminal and try the following commands:

dpkg -S 'command name'

eg: dpkg -S /bin/ls

Sample output:

coreutils: /bin/ls

You can also obtain detailed status information about coreutils package, enter:

 dpkg -s coreutils

Sample output:

Package: coreutils
Essential: yes
Status: install ok installed
Priority: required
Section: utils
Installed-Size: 9040
Maintainer: Ubuntu Core Developers 
Architecture: i386
Version: 5.97-5.3ubuntu3
Replaces: textutils, shellutils, fileutils, stat, debianutils (<= 2.3.1), dpkg (<< 1.13.2)
Provides: textutils, shellutils, fileutils
Pre-Depends: libacl1 (>= 2.2.11-1), libc6 (>= 2.6-1), libselinux1 (>= 2.0.15)
Conflicts: stat
Description: The GNU core utilities
 This package contains the essential basic system utilities.
 .
 Specifically, this package includes:
 basename cat chgrp chmod chown chroot cksum comm cp csplit cut date dd df dir
 dircolors dirname du echo env expand expr factor false fmt fold groups head
 hostid id install join link ln logname ls md5sum mkdir mkfifo mknod mv nice nl
 nohup od paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir
 sha1sum seq shred sleep sort split stat stty sum sync tac tail tee test touch
 tr true tsort tty uname unexpand uniq unlink users vdir wc who whoami yes
Original-Maintainer: Michael Stone 

Solution 2:

there is another one method, maybe a little silly, but faster than previous ones :) just mistype a command and you will get correct command name and package it came from.

Sample output:

pawel@pawel-desktop:/var/www$ sfn
No command 'sfn' found, did you mean:
 Command 'sn' from package 'mono-devel' (main)
 Command 'sfc' from package 'syfi-bin' (universe)
 Command 'svn' from package 'subversion' (main)
sfn: command not found

Solution 3:

You can also do it with one line:

dpkg -S $(which command)

For example, I want to know what package contains ls:

dpkg -S $(which ls)

And here is the output:

coreutils: /bin/ls

So now I know that ls command, /bin/ls file, comes from coreutils package.

Solution 4:

From the command name you can use the 'type' and 'dpkg' commands to determine the package which is responsible for their installation. For example to find out which package installed the command 'who' you could do the following commands at a command prompt:

$ type who
who is /usr/bin/who
$ dpkg -S /usr/bin/who
coreutils: /usr/bin/who