I'm curious what commands a certain package provides my system with. By command, I mean an in-path executable that I can run from the command line (ls
, grep
, sed
, etc).
I'm not trying to work out the package from the command, which can be done with:
dpkg -S `which command`
I want the opposite, a list of commands from a package.
Best Answer
The following little loop will handle this with installed packages.
How it works:
dpkg -L package
generates a list of all the files in a package which we iterate through.${f##*/}
andtype -P command
we see if that command is both in the path and that its path equals the file we started with.[[ condition ]] && command
is just a bash shorthand for an if..then statement.It's important to note that not all packages contain the commands you would expect them to. Apache is split out over multiple packages (with
-common
and-bin
subpackages) and thevlc
command isn't in thevlc
package, it's invlc-nox
. There are many examples like that.This can be adapted per Gilles's idea, doing a string match instead of actually checking, but keeping it all in one bash process (and still using the whole path).
The major difference here is the
[[$f =~ ^${PATH//:/|} ]]
. That's an in-Bash regex search. The${PATH//:/|}
part is taking the contents of $PATH and is hacking them into a dirty little regex. The condition should check the string begins with part of the path.