I use the command
$ whereis rm /bin/rm
Then I try
$ which rm /usr/local/opt/coreutils/libexec/gnubin/rm
The results are different... so which
rm will be called when I run a command like
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
whichsearches 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
whereisdoesn't search if you'd added to your PATH).
whereissearches the standard *nix locations for a specified command.
$ 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
whereissearches for "possibly useful" files, while
whichonly searches for executables.
I rarely use
whereis. On the other hand,
whichis very useful, specially in scripts.
whichis 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
According to manual of
which returns the pathnames of the files (or links) which would be executed in the current environment, had its arguments been given as commands in a strictly POSIX-conformant shell. It does this by searching the PATH for executable files matching the names of the arguments. It does not canonicalize path names.
According to manual of
whereis locates the binary, source and manual files for the specified command names. The supplied names are first stripped of leading pathname components and any (single) trailing extension of the form .ext (for example: .c) Prefixes of s. resulting from use of source code control are also dealt with. whereis then attempts to locate the desired program in the standard Linux places, and in the places specified by $PATH and $MANPATH.
So clearly there is a very thin of difference among them.
which results include path of executable file while
whereis results in binaries and documentation.
For example, consider java:
which results in just one path, i.e. path of java executable file
whereis results in about paths, i.e. path of java binary, source and manual
java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz