which, whence


Search PATH for a program:

$ which ls
The original Bourne shell (sh) had no command like which. The csh introduced "which". Ksh uses "whence", and bash etc. will use "which".

If the thing being searched for is a shell builtin like "cd", "which" and "whence" won't find it, but how that is reported can be very different:

( ksh on SCO OSR5 )
$ whence cd
( bash on Mac OS X)
$ which cd
no cd in /bin /sbin /usr/bin /usr/sbin /Users/apl/bin /usr/local/bin /Developer/Tools
( tcsh on Mac OS X)
% which cd
cd: shell built-in command.

You may also have a "whereis" command, though this usually only searches the "standard" directories: it probably won't look anywhere you might have added to your PATH.

On OSR5 and some other POSIX compliant platforms, /bin/cd and other common shell builtins exist, so you must call the actual binary if that's what you need.

Got something to add? Send me email.

1 comment

Increase ad revenue 50-250% with Ezoic

More Articles by

Find me on Google+

© Tony Lawrence

On OSR5, whence can be given multiple args:

$ whence ls getty marry


Kerio Samepage

Have you tried Searching this site?

Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

We made the buttons on the screen look so good you'll want to lick them. (Steve Jobs)

This post tagged: