How to find commands associated to a package?

5,483

Solution 1

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.

Solution 2

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
Share:
5,483

Related videos on Youtube

Pablo A
Author by

Pablo A

Updated on September 18, 2022

Comments

  • Pablo A
    Pablo A over 1 year

    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?

  • Pablo A
    Pablo A over 6 years
    What I asked was the opposite. Not getPackage(command) but getCommands(package).
  • thrig
    thrig over 6 years
    Not everything lives in /usr/bin though e.g. mailman hides commands under /usr/lib/mailman/bin
  • Pablo A
    Pablo A over 6 years
    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
    Pablo A over 6 years
    Sure, that's why I put optionally. I extended the answer to make it more clear.
  • Kusalananda
    Kusalananda over 6 years
    Shorter with just dpkg -L package | grep '/bin/'
  • Pablo A
    Pablo A over 6 years
    @Kusalananda It's impossible for a package command to be in a directory that does not contain "/bin/" on it path?
  • Kusalananda
    Kusalananda over 6 years
    @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.
  • Pablo A
    Pablo A over 6 years
    Leve some paths out (echo $PATH | tr : \\n | egrep -v "/sbin|/bin") but usually works, I added to my answer. Thanks!