Reading the man pages about the "whereis" command on my Debian 'wheezy' linux, it shows that the file interested are:

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}

I assume that those are the hard-coded search paths, but why I get this:

root@kali:/bin# whereis gnome
gnome: /usr/share/gnome
root@kali:/bin#

Why does it show it? Since it is not not on the assumed path?

... and moreover it is a directory, not a binary, source or manual.

Well, that's because it searches in the... uh... hmmm. It looks like someone made changes to the source code but forgot to update the documentation. Here's the complete list of folders that are searched, direct from the source code:

static const char *bindirs[] = {
    "/usr/bin",
    "/usr/sbin",
    "/usr/lib",
    "/usr/lib64",
    "/bin",
    "/sbin",
    "/etc",
    "/usr/etc",
    "/lib",
    "/lib64",
    "/usr/games",
    "/usr/games/bin",
    "/usr/games/lib",
    "/usr/emacs/etc",
    "/usr/lib/emacs/*/etc",
    "/usr/TeX/bin",
    "/usr/tex/bin",
    "/usr/interviews/bin/LINUX",

    "/usr/X11R6/bin",
    "/usr/X386/bin",
    "/usr/bin/X11",
    "/usr/X11/bin",
    "/usr/X11R5/bin",

    "/usr/local/bin",
    "/usr/local/sbin",
    "/usr/local/etc",
    "/usr/local/lib",
    "/usr/local/games",
    "/usr/local/games/bin",
    "/usr/local/emacs/etc",
    "/usr/local/TeX/bin",
    "/usr/local/tex/bin",
    "/usr/local/bin/X11",

    "/usr/contrib",
    "/usr/hosts",
    "/usr/include",

    "/usr/g++-include",

    "/usr/ucb",
    "/usr/old",
    "/usr/new",
    "/usr/local",
    "/usr/libexec",
    "/usr/share",

    "/opt/*/bin",
    NULL
};

static const char *mandirs[] = {
    "/usr/man/*",
    "/usr/share/man/*",
    "/usr/X386/man/*",
    "/usr/X11/man/*",
    "/usr/TeX/man/*",
    "/usr/interviews/man/mann",
    NULL
};

static const char *srcdirs[] = {
    "/usr/src/*",
    "/usr/src/lib/libc/*",
    "/usr/src/lib/libc/net/*",
    "/usr/src/ucb/pascal",
    "/usr/src/ucb/pascal/utilities",
    "/usr/src/undoc",
    NULL
};

Source

The best idea I have, is to look into the source code.

There are three static arrays defined, one for binary search path, one for man pages and one for sources. They include the following dirs (hardcoded as mentioned in the BUGS section of the man page, oder adjustable with the command line options -B, -M, -S, resp.) -- taken from version 2.23:

  • binary search path

    "/usr/bin",
    "/usr/sbin",
    "/usr/lib",
    "/usr/lib64",
    "/bin",
    "/sbin",
    "/etc",
    "/usr/etc",
    "/lib",
    "/lib64",
    "/usr/games",
    "/usr/games/bin",
    "/usr/games/lib",
    "/usr/emacs/etc",
    "/usr/lib/emacs/*/etc",
    "/usr/TeX/bin",
    "/usr/tex/bin",
    "/usr/interviews/bin/LINUX",
    "/usr/X11R6/bin",
    "/usr/X386/bin",
    "/usr/bin/X11",
    "/usr/X11/bin",
    "/usr/X11R5/bin",
    "/usr/local/bin",
    "/usr/local/sbin",
    "/usr/local/etc",
    "/usr/local/lib",
    "/usr/local/games",
    "/usr/local/games/bin",
    "/usr/local/emacs/etc",
    "/usr/local/TeX/bin",
    "/usr/local/tex/bin",
    "/usr/local/bin/X11",
    "/usr/contrib",
    "/usr/hosts",
    "/usr/include",
    "/usr/g++-include",
    "/usr/ucb",
    "/usr/old",
    "/usr/new",
    "/usr/local",
    "/usr/libexec",
    "/usr/share",
    "/opt/*/bin"
    
  • man page search path

    "/usr/man/*",
    "/usr/share/man/*",
    "/usr/X386/man/*",
    "/usr/X11/man/*",
    "/usr/TeX/man/*",
    "/usr/interviews/man/mann"
    
  • source search path

    "/usr/src/*",
    "/usr/src/lib/libc/*",
    "/usr/src/lib/libc/net/*",
    "/usr/src/ucb/pascal",
    "/usr/src/ucb/pascal/utilities",
    "/usr/src/undoc"
    

In addition $PATH and $MANPATH are taken into account, too.

For the last part of your question, why folders are found as binaries, I speculate that whereis finds everything as binary in the specified folders, even _un_executable (empty) files:

$ touch /usr/share/foo
$ whereis foo
foo: /usr/share/foo

What's the intention of that -- I don't know. But all in all I think whereis is a little bit outdated. To find executables the shell builtin where -a [command] is much more appropriate.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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