1

Sometimes I find myself installing a package and then trying to run a command using the same name, like with geoip-bin package:

$ sudo apt install geoip-bin

[...]

$ geoip-bin
geoip-bin: command not found

How may I find all the commands associated with a given package?

0
3

You can use the command dpkg:

dpkg -S $(which <command>)

e,g:

$ dpkg -S $(which cp)
coreutils: /bin/cp

the command cp is a part of coreutils package.

To see all commands associated to coreutils package:

$dpkg -s coreutils

Specifically, this package includes:

 arch base64 basename cat chcon chgrp chmod chown chroot cksum comm cp
 csplit cut date dd df dir dircolors dirname du echo env expand expr
 factor false flock fmt fold groups head hostid id install join link ln
 logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup nproc numfmt
 od paste pathchk pinky pr printenv printf ptx pwd readlink realpath rm
 rmdir runcon sha*sum seq shred sleep sort split stat stty sum sync tac
 tail tee test timeout touch tr true truncate tsort tty uname unexpand
 uniq unlink users vdir wc who whoami yes
3
  • What I asked was the opposite. Not getPackage(command) but getCommands(package). – Pablo A Sep 26 '17 at 18:32
  • But that's particular to coreutils package, they decide to put that on Description metadata field. Use dpkg -s geoip-bin (or apt show) and you won't get a list of available commands. – Pablo A Sep 26 '17 at 18:45
  • correct dpkg -s will not show all the available commands, dlocate should be the easy and the fast way (Gille and Terdon answer's) – GAD3R Sep 27 '17 at 8:33
3

dpkg -L

-L, --listfiles package-name List files installed to your system from package-name.

Two alternatives:

  • Usually works just: dpkg -L byobu | egrep '/bin/|/sbin/' (or even with grep bin if you don't care getting some false positives).
  • Or

    dpkg -L byobu | xargs which
    
  • Or with some bash magic:

    for f in $(dpkg -L geoip-bin) ; do test -x $f -a ! -d $f && echo $f ; done
    

    Optionally you could add | grep "/usr/bin/" at the end to list executables files on that particular folder.

geoiplookup was the command of geoip-bin. I also found this very useful to learn about other commands of any package.

6
  • Not everything lives in /usr/bin though e.g. mailman hides commands under /usr/lib/mailman/bin – thrig Sep 26 '17 at 18:42
  • Sure, that's why I put optionally. I extended the answer to make it more clear. – Pablo A Sep 26 '17 at 18:49
  • Shorter with just dpkg -L package | grep '/bin/' – Kusalananda Sep 26 '17 at 19:29
  • @Kusalananda It's impossible for a package command to be in a directory that does not contain "/bin/" on it path? – Pablo A Sep 26 '17 at 19:34
  • @PabloBianchi No, but if you look at your $PATH, it mostly contains /bin/ directories, right? You could change it to bin/ to also catch any sbin commands. – Kusalananda Sep 26 '17 at 19:37

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