Skip to content
shellmap

whichLocate an executable in PATH and print its full path across all 5 shells

Equivalents in every shell

Bashunix
which python3

External `/usr/bin/which` binary, not a bash builtin. Prints the first PATH match and exits 0; non-zero (often 1) when the command is not found.

Zshunix
which python3

Zsh ships its own `which` builtin in addition to the external binary. The builtin behaves like `whence -c` and can also resolve aliases and functions.

Fishunix
which python3

Fish uses the external `which` binary. For builtin-aware lookup prefer `type python3` instead.

PowerShellwindows
Get-Command python3

Aliased as `gcm`. Returns a `CommandInfo` object rather than plain text; read `.Source` (or `.Path` for `Application` types) to get just the path string.

cmd.exewindows
where python3

Built-in since Windows Server 2003 / Vista. `where` prints *all* PATH matches, not just the first — a key behavioural difference from Unix `which`.

Worked examples

Find where the python3 binary lives

Bash
which python3
PowerShell
(Get-Command python3).Source
cmd.exe
where python3

Test in a script whether a command exists

Bash
if which jq >/dev/null 2>&1; then echo yes; fi
Fish
if which jq >/dev/null 2>&1; echo yes; end
PowerShell
if (Get-Command jq -ErrorAction SilentlyContinue) { "yes" }
cmd.exe
where jq >nul 2>&1 && echo yes

List every PATH match, not just the first

Bash
which -a python3
PowerShell
Get-Command python3 -All | Select-Object -ExpandProperty Source
cmd.exe
where python3

Gotchas

  • `which` on Linux is GNU `which`; on macOS it is the BSD version. The BSD version does not accept `-a` on older systems — use `type -a` for builtin-aware multi-match listing.
  • Bash `which` does NOT resolve aliases or shell functions because it is an external binary that knows nothing about your current shell. Use `type` (bash/zsh) or `command -v` for shell-aware lookup.
  • PowerShell `Get-Command` returns an *object*. `Get-Command python3` prints a table; `.Source` is the bare path string. Piping to text-only consumers needs the explicit property.
  • Windows `where` looks in PATH *and* the current directory. Unix `which` ignores the current directory unless `.` is in PATH (which is a security anti-pattern). Account for the difference when porting scripts.
  • On bare Windows there is no `which.exe` — running `which` in cmd.exe or PowerShell errors out. Use `where` (cmd) or `Get-Command` (PowerShell), or rely on Git Bash / WSL for the Unix command.

WSL & PowerShell Core notes

pwshPowerShell Core on Linux/macOS does NOT alias `which` to `Get-Command` — the system `/usr/bin/which` resolves first. On Windows pwsh, `where` is a cmd-only built-in (not the binary `where.exe`), so PowerShell ships its own `where` alias for the `Where-Object` cmdlet — calling `where python3` in PowerShell silently produces empty output instead of resolving the path.
WSLWSL Linux has its own `/usr/bin/which`; the Windows `where.exe` is reachable via interop (`where.exe python3`). The two answer different questions — `which` consults the WSL `$PATH`, `where.exe` consults the Windows `%PATH%`.

Related glossary

Common tasks using which

Related commands