where
Locate command binaries in standard locations
TLDR
Find all instances of a command
SYNOPSIS
where [ -apmqsz ] name ...
This syntax primarily applies to the zsh built-in where command. If where is an alias in your shell, its synopsis will depend on the command it aliases (e.g., `whereis` or `which`).
PARAMETERS
-a
Display all matching executables found in the PATH, instead of just the first one.
-p
Search only in the directories specified by the current PATH environment variable.
-m
Use the shell's command hash table to find matches. This reflects what the shell would actually execute.
-q
Quiet mode. Suppresses all output; only the exit status indicates success (0) or failure (non-zero).
-s
Show only the first match found. This is the default behavior if -a is not specified.
-z
Do not use the shell's command hash table; search directories explicitly.
DESCRIPTION
where is not a standard standalone utility found universally across all Linux distributions. Instead, it is most commonly encountered as a built-in command in the Z shell (zsh). In zsh, where functions similarly to `which -a` or `type -a`, displaying all occurrences of a specified command found within the directories listed in the user's PATH environment variable. If where is present in other shells like Bash, it is typically a user-defined alias or a shell function, often configured to invoke `whereis` or `which -a`. Its primary purpose is to help users identify the exact location of command executables, useful for debugging PATH issues or ensuring the correct version of a command is being invoked.
CAVEATS
where is not a universal standalone command across all Linux systems. Its availability and behavior depend heavily on the shell being used:
• In Z shell (zsh), where is a built-in command with specific options as described.
• In other shells like Bash, where is generally not a built-in or standard utility. If available, it's typically implemented as a user-defined alias or shell function, often pointing to whereis or which -a. Consequently, its exact functionality and accepted options may vary significantly based on how it's defined. Always check your shell's configuration (`type where` or `alias where`) if you're unsure.
TYPICAL USAGE
When available, where is commonly used to find the full path of a command. For example, `where python` would show you the location of the Python executable. This is particularly useful when multiple versions of a program might exist on your system, and you need to verify which one is being invoked based on your PATH.
HISTORY
The where command primarily originated as a built-in feature of the Z shell (zsh), providing a convenient way to locate executable files. Its functionality is similar to earlier utilities like `which` but often offers additional options or a slightly different default behavior (e.g., showing all matches by default in some configurations or implicitly similar to `which -a`). While not a part of the original Unix toolset, its utility led to its adoption or emulation in other shell environments, often via aliases or functions to provide a consistent experience for users familiar with its behavior in zsh or other operating systems (like the Windows `where` command).