What is the difference between whereis and which commands
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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)
whereis searches through a list of certain directories (listed in man) for source/binary and manuals sections.
which searches only for binaries in $PATH.
"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:
...
FILES
/{bin,sbin,etc}
/usr/{lib,bin,old,new,local,games,include,etc,src,man,sbin,
X386,TeX,g++-include}
/usr/local/{X386,TeX,X11,include,lib,man,etc,bin,games,emacs}
BUGS
...
whereis has a hard-coded path, so may not always find what you're look-
ing for.
8 May 1994 WHEREIS(1)
It will not look in your own bin, or any other bin directory not listed above.
Another note, which searches your aliases then your $PATH and gives you the FIRST executable it finds, whereis tells you everything it finds.
Well, sir, this all depends on which which you are using, and which which will indicate which which is in actual use which is exactly which fact one wishes to discover when wondering which which, and which which performs which behavior.
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."
....which means you haven't looked very hard:
Code:
$ alias hi
alias hi='history'
$ which hi
alias hi='history'
$ alias
$ /usr/bin/which hi
/usr/bin/which: no hi in (/home/mrc/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/sbin:/sbin:.:/home/mrc/bin)
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.