type -a

October 23, 2014

I mentioned previously that which -a is what you want to use to find what command you’re about to run.

I was wrong.

I found accidentally, probably while reading something on stackoverflow, that type -a is a better-in-every-way replacement for which -a. Compare:

% which -a ls

% type -a ls
ls is aliased to 'ls --color=auto'
ls is /Users/jpalardy/local/bin/ls
ls is /bin/ls

Not only does type -a give me all the same information, but it also tells me about aliases and functions. Consider what happens for functions which do not have corresponding executables in the PATH:

% which -a gril
                                #   -- no output --

% type -a gril
gril is a function
gril ()
  grep -il "$@"

It tells me it’s a function and it shows me its definition. type -a has decreased, substantially, the amount of grepping my dotfiles trying to remember how certain functions work.

Discuss on Twitter