Skip to content
shellmap

get-commandShow where a command resolves — which / type / command -v across all 5 shells

Equivalents in every shell

Bashunix
command -v jq

POSIX-portable. Prints a path for external commands, the name for builtins/functions/aliases. Exit status non-zero if not found — the canonical `if command -v X` script idiom. `which` (external on most Linuxes, builtin on csh) is the older form but is not POSIX-blessed and behaves differently on Alpine/BusyBox.

Zshunix
whence -p jq

Zsh `whence` is the rich introspector: `-p` external-only path, `-c` show only the type, `-v` verbose. The POSIX `command -v jq` and the bash `type jq` also work. Zsh prefers a builtin over an external when both exist.

Fishunix
type -p jq

Fish `type -p` prints the path (no fork); `type -q` is the silent existence check (exit 0 if found, 1 if not). `command -v` works since fish 2.7. Aliases in fish are functions, so `type jq` shows function bodies for aliased commands.

PowerShellwindows
Get-Command jq

Aliased as `gcm`. Returns a `[CommandInfo]` object — `.Source` is the resolved path, `.CommandType` is Alias / Function / Cmdlet / Application / ExternalScript, `.Parameters` is the parameter dictionary. Errors loudly when missing — pair with `-ErrorAction SilentlyContinue` in existence-check scripts.

cmd.exewindows
where jq

Built-in `where`. Prints every matching PATH entry (`/F` quotes the path; `/Q` quiet mode for existence checks). Errors if not found. cmd has no equivalent to `command -v` for builtins — `where cd` errors because `cd` is internal.

Worked examples

Resolve a command to its path

Bash
command -v ffmpeg
Fish
type -p ffmpeg
PowerShell
(Get-Command ffmpeg).Source
cmd.exe
where ffmpeg

Script-friendly existence check

Bash
command -v jq >/dev/null && echo found
PowerShell
if (Get-Command jq -ErrorAction SilentlyContinue) { "found" }
cmd.exe
where /Q jq && echo found

List every kind of binding for a name

Bash
type -a python
PowerShell
Get-Command python -All

Gotchas

  • `Get-Command <name>` THROWS a non-terminating error (red text on stderr) by default when the command is missing — corrupts otherwise-silent script output. Always pair with `-ErrorAction SilentlyContinue` for existence checks, or wrap in a `try { Get-Command X } catch { $false }`.
  • `-All` returns every binding in PRECEDENCE order — alias first, then function, then cmdlet, then external. The default (no `-All`) returns only the FIRST match. If `python` is both a function and an external binary, plain `Get-Command python` shows only the function.
  • `(Get-Command X).Source` is the resolved path for `Application` / `ExternalScript` types. For `Cmdlet` it's the module path; for `Function` and `Alias` it's empty. Scripts that blindly index `.Source` get `$null` on builtins — guard with a `.CommandType` check first.
  • Wildcards: `Get-Command Get-*` lists every cmdlet whose name starts with `Get-`. Combined with `-Module` you can filter to a specific module, useful for discovery. Bash users miss this — `command -v Get-*` does NOT pattern-match.
  • On Linux/macOS pwsh, `Get-Command` resolves through PowerShell's own command table FIRST, then `$PATH`. If a function or alias shadows an external (e.g. `function ls { ... }` in `$PROFILE`), `Get-Command ls` returns the function, not `/bin/ls`. Use `Get-Command -CommandType Application ls` to bypass.

WSL & PowerShell Core notes

pwsh`Get-Command` is identical on every pwsh platform. The `gcm` alias is universal. On Linux/macOS pwsh, the PowerShell `$PATH` integration is automatic — the system `/usr/bin` directories are searched after the PowerShell command table, in the order the PATH env var dictates. There is no platform-specific cmdlet behaviour beyond which commands happen to exist on the host.
WSLInside WSL bash, `command -v` is the POSIX builtin. WSL's interop automatically appends Windows-side PATH directories to the WSL `$PATH` (controlled by `interop.appendWindowsPath` in `/etc/wsl.conf`, default true), so `command -v notepad.exe` resolves to a Windows-side path. Set `appendWindowsPath = false` for hermetic build scripts that must not pick up Windows binaries.

Related commands