Skip to content

Instantly share code, notes, and snippets.

@mcandre
Last active October 23, 2024 20:17
Show Gist options
  • Save mcandre/3075809d09d8b5b62253eded763a2cf9 to your computer and use it in GitHub Desktop.
Save mcandre/3075809d09d8b5b62253eded763a2cf9 to your computer and use it in GitHub Desktop.
How to Locate Commands

How to Locate Commands

Feeling lost?

You can verify the location of commands, and distinguish between different types of commands (executable binaries and scripts vs. shell built-in commands vs. aliases) with a variety of analysis commands.

For common UNIX, esp. POSIX compliant shells like ash, bash, dash, ksh, posh, zsh and WLS, try:

  • command -v <name>
  • type <name>
  • which <name>
  • where
  • echo "$PATH"
  • (with root privileges) find / -name <name> -print 2>/dev/null

Note that UNIX commands and dot sourcable environment scripts, are not normally available to operate unless invoking the name relative to a file path, e.g. ./<name>

For Command Prompt, try:

  • where <name>
  • echo %PATH%
  • Explorer -> Search

Note that MS-DOS Batch scripts (*.bat, *.cmd) may not be accessible to all shells.

For PowerShell, try:

  • Get-Command <name>
  • echo $env:Path
  • Explorer -> Search

Note that PowerShell scripts (*.ps1) often require a wrapping command powershell -Command <name>, when accessing from other shells like Command Prompt, WSL, etc.

When in doubt, design scripts as (ideally fully static) compiled, binary executable programs, for better portability across shells. Go, Rust, C, and C++ have relatively high potential for portable shell usage, as long as the programs and dependencies call portable API's, such as standard library calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment