I want to use the which command to see which executable is actually being invoked, but the defensive noglob aliases keep getting in the way.

Is there a shortcut that I can use to find which executable is invoked when the command is aliased ?

I am using the zsh shell.

2 Answers 2


You can use which -a COMMAND (or where COMMAND or whence -ca COMMAND) to find all occurences of COMMAND in the command path.

For example:

% alias ls='noglob ls'
% ls () /bin/ls
% which ls
ls: aliased to noglob ls
% which -a ls
ls: aliased to noglob ls
ls () {

As aliases are replaced in the command line before anything is executed, the second command in the list is the one you are looking for (assuming of course that the first line is somehow aliased to the same name)

  • Can you please explain why does it work? There is no man entry for where or whence. Sep 15, 2020 at 7:13
  • 2
    In zsh which, where and whence are all built-in commands, with which being equivalent to whence -c and where being equivalent to whence -ca. Their documentation can be found in man zshbuiltins. While there is a manpage for which, it is not for the built-in, but for the external command (usually /bin/which or /usr/bin/which). See also the output of the command which -a which.
    – Adaephon
    Sep 23, 2020 at 15:06

Use which -p e.g.:

✗ which ls
ls: aliased to ls --color=tty
✗ which -p ls

From https://linux.die.net/man/1/zshbuiltins:

(whence) -p

Do a path search for name even if it is an alias, reserved word, shell function or builtin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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