Is it possible to use the which
command on a glob pattern to return multiple results?
For example, I want to know the full path of all my latex
commands. I can try:
[lucas@lucas-ThinkPad-W520]/home/lucas$ which latex
/usr/bin/latex
or:
[lucas@lucas-ThinkPad-W520]/home/lucas$ which pdflatex
/usr/bin/pdflatex
or:
[lucas@lucas-ThinkPad-W520]/home/lucas$ which xelatex
/usr/bin/xelatex
but I cannot use:
[lucas@lucas-ThinkPad-W520]/home/lucas$ which *latex
which returns nothing.
Any suggestions on how to use a glob pattern with the which
command?
Best Answer
With
zsh
(note thatwhich
is only built intcsh
orzsh
, in other shells it can give random results, usetype
in Bourne like shells):Or (if you only want to consider executables and not functions, aliases...):
With other Bourne-like shells, you could do:
And then:
That should work more the most common values of
$PATH
. It will omit the entries in the current directory if$PATH
ends in:
(like/bin:/usr/bin:
)