brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: where.exe finds a program on your PATH, like which on Linux

Tools
~/tips/tip-windows-where-exe

where python

Lists where a program or file is found on PATH, in the order Windows uses it.

When a command runs the wrong version of a tool, the first question is which file Windows actually starts. where answers that, with one catch in PowerShell. I’d start with it whenever a tool behaves like a different version.

In Command Prompt:

where python
where /r C:\Users\<user> notes.txt

By default where searches the current directory and every folder in your PATH, and it lists all matches in the order Windows would find them. The first line is the one that runs. If you leave off the file extension, it tries the ones in the PATHEXT variable, such as .exe and .bat.

A few options:

where /r C:\ test         # search recursively from a folder
where /q git               # no output, only exit code 0 or 1
where /t node              # show size and modified date
where $public:*.*          # search folders listed in an environment variable

The catch: in PowerShell, where is an alias for Where-Object, so typing where python there does not do what you expect. Type the full name with the extension, where.exe python, or use the PowerShell cmdlet Get-Command python.

Other caveats: it matches files by name, so it tells you nothing about aliases or functions defined in your shell. A recursive search over a whole drive can take a while. The patterns accept * and ? wildcards, and /r should not be combined with the $ENV: or Path: pattern forms.

The exit code (0 for found, 1 for not found) makes it usable in batch scripts, to check that a tool is installed before running it.

Further reading: Microsoft Learn: where

More Tools tips shuf -n 3 films.txt xmllint --format feed.xml pdftotext -layout invoice.pdf invoice.txt qrencode -t ANSIUTF8 'https://example.com/a/long/path?id=12345' ffprobe -v error -show_entries format=duration -of default=nw=1:nk=1 input.mp4 All Tools tips (14) All topics

Link