The Computer Oracle

"whereis" and "which" return different paths in Mac OS X

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Music Box Puzzles

--

Chapters
00:00 &Quot;Whereis&Quot; And &Quot;Which&Quot; Return Different Paths In Mac Os X
00:37 Accepted Answer Score 39
01:40 Thank you

--

Full question
https://superuser.com/questions/430002/w...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#macos #path #macports #which

#avk47



ACCEPTED ANSWER

Score 39


In the manpage of whereis, it clearly says (emphasis mine):

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

The path searched is the string returned by the sysctl(8) utility for the ``user.cs_path'' string

Contrary to that, which is the tool commonly used to check where a binary is for your user's path.

The which utility takes a list of command names and searches the path for each executable file that would be run had these commands actually been invoked.

That explains your difference, since /opt/local/bin is not a system-wide "standard" path—after all, MacPorts is a completely optional installation—and sysctl only has /usr/bin:/bin:/usr/sbin:/sbin in its user.cs_path per default.

In general, stick to which or which -a to find a binary rather than using whereis.


You can theoretically change user.cs_path through

sysctl -w user.cs_path=/opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

but I don't know if that is such a good idea.