Skip to content

/commands/cmd/where-find-executable

where: find which executable runs for a command in Windows (like which)

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
Command Prompt (cmd)
versions
Windows 10, Windows 11, Windows Server 2016+
os
windows

where python prints the full path of every file named python plus a PATHEXT extension (.exe, .cmd, .bat …) found in the current folder and then in each PATH folder, in search order. The first line is the one cmd runs. It is the Windows counterpart of which -a. Nothing found prints INFO: Could not find files for the given pattern(s). and sets ERRORLEVEL to 1.

cmd
where python
where git node npm

Examples

cmd
mkdir bin
> bin\tool.cmd echo @echo tool
> notes.txt echo x
where /r . tool.cmd notes.txt
set "PATH=%CD%\bin;%PATH%"
where tool
where /q nosuchtool
echo where /q: ERRORLEVEL=%ERRORLEVEL%
where nosuchtool 2>&1
echo where: ERRORLEVEL=%ERRORLEVEL%

Output

/tmp/work/notes.txt
/tmp/work/bin/tool.cmd
/tmp/work/bin/tool.cmd
where /q: ERRORLEVEL=1
INFO: Could not find files for the given pattern(s).
where: ERRORLEVEL=1

Options

OptionMeaning
where namesearch the current folder and PATH, using PATHEXT when no extension is given
where /r folder patternsearch a folder tree recursively instead of PATH
where $VAR:patternsearch the folders listed in another variable, for example where $PYTHONPATH:*.py
where /q namequiet: no output, only ERRORLEVEL (0 found, 1 not found)
where /t namealso print size, date and time
where *.exewildcards * and ? are allowed

Typical uses

  • Two versions installed, wrong one runs: where python shows both; the first wins. Reorder PATH or remove the stale entry. The Microsoft Store alias %LOCALAPPDATA%\Microsoft\WindowsApps\python.exe often appears first.
  • "is not recognized": if where name finds nothing, the program is not in any PATH folder; see is not recognized as an internal or external command.
  • In a batch file: where /q git || (echo git is required & exit /b 1).

Sources