41

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

2
  • 1
    as far as I know a "file" is different from a "command" (even if at least a little bit). Having the same answer doesn't mean that the question is the same. – Mina Michael Nov 29 '17 at 17:38
  • @MinaMichael With the exception of built-in commands in a shell (like 'ls' in bash) commands are programs run from your disk, and the programs are in fact files... – Charles Green Nov 29 '17 at 18:55
50

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 
1
  • Not useful for uninstalled packages. For example, if you try: "dpkg -S add-apt-repo" there will be no result of searching – Mohsen Abasi Dec 4 '17 at 9:09
14

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
3
  • 3
    That is indeed very silly! – LassePoulsen Nov 18 '10 at 10:56
  • 4
    but it works :P – Praweł Nov 18 '10 at 11:53
  • With something like this, Ubuntu basically goes and runs something like: command_not_found_handle 'sfn'. The longer form also helpfully "pretends" the program is not there (even if it is) and tells you what you want to know, so that you can put the exact command name without having to mistype it. – mwfearnley Jul 31 '16 at 16:18
6

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
5

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.

0
2

Now for a completely different approach.

Go to packages.ubuntu.com and follow your nose. In particular, scroll down to "Search the contents of packages" and enter the file name or system command.

1
  • Your resolution has a problem in that it will show the source of a package that is available from the default repository. Those sources will rarely be the source of a problem. In trouble shooting a problem command, the user wants to find out the source of the command he on his actual installation. That might be a PPA our some other repository added to his sources.list. There's also a change the particular command on his system might be from a complied instance that he doesn't remember. He can run the command, but the dpkg -s search will be blank... which would be valuable information. – L. D. James Feb 16 '17 at 9:23
0
  1. drop to a command prompt (Menu > Applications > Accessories > Terminal)
  2. enter dpkg-query --search 'command' where 'command' is the command whose owning package you're trying to find.

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