Quick take: Use which cmd to find the path of the executable that runs, whereis cmd to find its binary, source, and man pages, and type cmd to see whether it is a binary, alias, function, or shell built-in.

Introduction

When you want to know exactly what runs when you type a command, three tools answer slightly different questions. which shows the path of the executable found in your PATH, whereis locates the binary along with its source and manual, and type reveals whether the name is a binary, alias, function, or shell built-in.

This guide covers each tool, how they differ, and when to reach for which one.

Syntax

The basic syntax of the which and whereis command is:

which COMMAND
whereis COMMAND
type COMMAND

Common Options and Parameters

The most useful options and parameters for the which and whereis command:

OptionDescription
which cmdPrint the full path of the executable that PATH would run.
which -a cmdPrint all matching executables in PATH, not just the first.
whereis cmdLocate the binary, source, and man page for a command.
whereis -b cmdLocate only the binary.
type cmdShow how the shell interprets the name.
type -a cmdShow all interpretations (alias, builtin, and path).

Practical Examples

Real which and whereis commands you can run today:

# Find which python runs
which python3
# Show all matches in PATH
which -a python
# Find binary, source, and man page
whereis grep
# Is 'll' an alias, builtin, or binary?
type ll
# Show every interpretation of a name
type -a ls
# Check whether a command exists in a script
command -v docker >/dev/null && echo installed

Tips and Best Practices

  • type cmd is the most informative — it tells you if a name is an alias or shell built-in, which which cannot see.
  • In scripts, prefer command -v cmd to test whether a command exists; it is portable and built into the shell.
  • Use which -a when a command behaves unexpectedly to check for a second copy earlier in your PATH.

Final Thoughts

which, whereis, and type answer “what runs when I type this?” from three angles — the path, the full set of related files, and the shell's interpretation. For everyday “where is this binary?” use which; to see aliases and built-ins use type; and in scripts use command -v to check that a tool is installed.

FAQ: which and whereis Command in Linux

How do I find the path of a command in Linux?+

Use which command, for example which python3, to print the full path of the executable that your PATH would run.

What is the difference between which and whereis?+

which shows only the path of the executable that runs. whereis is broader, locating the binary, its source code, and its manual page — but it does not consider your PATH the way which does.

How do I tell if a command is an alias or a built-in?+

Use type command. Unlike which, type reports whether the name is a shell built-in, an alias, a function, or an external binary, and type -a shows all of them.

How do I check if a command is installed in a script?+

Use command -v: command -v docker >/dev/null && echo 'installed'. It is portable and returns success only if the command exists.

Why does which not find my alias?+

which inspects the filesystem PATH, not your shell's aliases and built-ins. Use type alias name to see aliases, since they exist only inside the shell.

Need help with Linux servers or infrastructure?

Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.

Hire Me for Support