which -a versus whereis

January 12, 2014

which -a

The command which is not a revelation, most people are aware of it. You type:

% which find
/usr/bin/find

and you get the full path of that executable. This is useful if you have multiple copies of an executable in different places in your PATH and you are wondering which one would be used.

Sometimes, you want to see ALL the matching executables in your PATH. That’s what the -a flag is for:

% which -a awk
/Users/jonathan/local/bin/awk
/usr/local/bin/awk
/usr/bin/awk

whereis

I had a vague notion that the whereis command was used to answer such questions. Unfortunately, it does something relatively useless:

The whereis utility checks the standard binary directories for the specified programs, printing out the paths of any it finds.

The key point being “standard binary directories”, that is “where stuff is supposed to be”, that is “I’m not going to check your PATH”… Here is whereis lying to me:

% whereis awk
/usr/bin/awk

I was enlightened by this answer on superuser.com.

Discuss on Twitter