Which command is used to give the location of the executable command to the console.
In windows, This command does not work and gives an error -‘which’ is not recognized as an internal or external command, operable program, or batch file.
C:>which derby ‘which’ is not recognized as an internal or external command, operable program, or batch file.
What is windows equivalent command of which command in Unix?
This tutorial covers about which command alternative in windows
- using where the command
- Cygwin tool
- PowerShell command
Where command in windows
Where command is equal to which command in Unix/Linux. It will only work from the windows 2003 version.
where the command prints the location of the file for a given search pattern. This search has given a search pattern in the environment variable path.
Here is a syntax
where [options] searchpattern
/R - recursive path for searching files /F - Displays the path of the file in double quotes /T - Displays file path metadata like size, modified date
It contains string or pattern of string using * for multiple, ? for a single character
Here is help documentation for the where.exe command
Here is an example where the command for the location of the ping command
C:\>where ping C:\Windows\System32\PING.EXE
suppose, you want to know the java executable location when there are multiple versions are included
C:\>where java A:\Java\jdk1.8.0\bin\java.exe C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
if you want to know the location for a word that starts with
jav, suffix * to it
if you used search pattern jav?, It searches for words
jav or and fourth letter might be any single letter or zero.
window PowerShell which alternative
Get-Command in PowerShell works the same as where command, This will work only in PowerShell command prompt only.
PS C:\> Get-Command java CommandType Name Version Source ----------- ---- ------- ------ Application java.exe 8.0.102... A:\Java\jdk1.8.0\bin\java.xe
Cygwin is a runtime tool that supports Linux commands in windows.
you can install from here
all the Linux commands work in windows, which command also works as expected
To sum up, Where command in DOS of windows and Get-Command in PowerShell are the alternatives to which command in windows.