What is the difference between whereis and which commands
Hello, I was wondering what was is the difference between the output of which and whereis when it comes to binaries. I mean when I type for example
whereis man I get something this (I'm using Ubuntu 8.04): man: /usr/bin/man /usr/local/man /usr/share/man /usr/share/man/man7/man.7.gz /usr/share/man/man1/man.1.gz If I type which man, I get this: /usr/bin/man If /usr/bin/man /usr/local/man /usr/share/man are supposed to be the binary files for the man command then why which only displays /usr/bin/man? I read the man pages but I couldn't figure it out. |
whereis will show you the location of the binary, the source, and the man pages for the command, whereas which will only show you the location of the binary for the command (these are straight out of the man entries, btw)
|
Or to add a little more, which uses your PATH to search for a executable.
|
One caveat for whereis:
Quote:
|
whereis searches through a list of certain directories (listed in man) for source/binary and manuals sections.
which searches only for binaries in $PATH. |
Jomen when you say "a hard coded path" what do you mean?
|
Another note, which searches your aliases then your $PATH and gives you the FIRST executable it finds, whereis tells you everything it finds.
HTH Forrest |
"hard coded path" in this context means the program only looks in a set of directories programmed into the program itself, such as:
Code:
man whereis: |
Quote:
|
I don't know if I'm supposed to laugh or say, "I haven't met a which which doesn't perform the way which I described."
|
Quote:
....which means you haven't looked very hard: Code:
$ alias hi |
I'll not cry, just add that most of my career I've used tcsh with a built in which, so don't go around meeting strange whiches often.
|
It is an important distinction.
Code that assumes builtin behavior is not portable, and causes problems when script is invoked from sub-shells which for speed reasons, or to control name space pollution, do not source shell startup files. But more importantly, it confuses new users who are not aware of the built-in vs external commands. Furthermore, many users still use or require standard Bourne shell behavior, or even ksh, which do not have built-ins (ksh has whence). This commentary isn't directed at you - it is merely for those who are interested in knowing about these distinctions. |
Also, the main point I was trying to make wasn't the fact that aliases are searched, but rathar that which will only show the FIRST thing it finds. This what what I initially thought you were disputing.
|
And a excellent point it is.
|
All times are GMT -5. The time now is 08:33 AM. |