up vote 2 down vote favorite
share [g+] share [fb]

What's the difference between which and whereis ?

link|improve this question

Why are there 2 votes to close this? Is that just because its been answered? – Mk12 Sep 12 '09 at 20:20
Probably because it's not a programming question. – Tom Sep 12 '09 at 20:23
I guess because it's not programming related and should be asked on superuser instead. – André Hoffmann Sep 12 '09 at 20:23
It's not a programming question, so it's better to ask it on one of the other sites. Depending on your perspective, it's either a superuser question or a serverfault question. – bigmattyh Sep 12 '09 at 20:23
Oh ya.. I didn't think of that. – Mk12 Sep 12 '09 at 20:40
show 2 more comments
feedback

migrated from stackoverflow.com Sep 12 '09 at 22:41

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 8 down vote accepted

How about learning about whereis and which using whatis?

$  whatis which
which                (1)  - shows the full path of (shell) commands

$  whatis whereis
whereis              (1)  - locate the binary, source, and manual page files for a command

Basically, whereis searches for "possibly useful" files, while which only searches for executables.

I rarely use whereis. On the other hand, which is very useful, specially in scripts. which is the answer for the following question: Where does this command come from?

$  which ls
/bin/ls

$  whereis ls
ls: /bin/ls /usr/share/man/man1p/ls.1p.bz2 /usr/share/man/man1/ls.1.bz2
link|improve this answer
1  
didn't know about whatis, thanks. – Mk12 Sep 12 '09 at 20:39
1  
BTW, I'd remove the "osx" tag, as this question applies to all unix variants (including Linux, BSD, Mac OS X, ...) – Denilson Sá Sep 12 '09 at 20:44
changed to unix – Mk12 Sep 12 '09 at 23:24
feedback

whereis searches the standard *nix locations for a specified command.

which searches your user-specific PATH (which may include some of the locations whereis searches, and may not include others - it might also include some places that whereis doesn't search if you'd added to your PATH)

link|improve this answer
What is *nix? – Mk12 Sep 12 '09 at 20:19
Unix, Linux etc. (Mac OS X belonging in the etc.) – Tom Sep 12 '09 at 20:23
Ohhh, haha, I always thought that stack overflow was censoring the U in unix whenever I saw that for some reason.. – Mk12 Sep 12 '09 at 22:19
Nope. Just a fairly common convention of creative wildcard use to refer to a family of similar operating systems. ;) – Dav Sep 12 '09 at 22:28
feedback

Quoting their man pages :

whereis :

whereis locates source/binary and manuals sections for specified files.

For instance :

$ whereis php
php: /usr/bin/php /usr/share/php /usr/share/man/man1/php.1.gz

ie, the "php" executable, and some other stuff (like man pages).


and which :

which returns the pathnames of the files which would be executed in the current environment

For instance :

$ which php
/usr/bin/php

ie, only the "php" executable.

link|improve this answer
Thanks for the examples. – Mk12 Sep 12 '09 at 20:21
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.