In Linux, Which command is used to give location of executable command to console.
In windows, This command does not works 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 tutorials covers about which command alternative in windows
- using where command
- cygwin tool
- powersheel command
Where command in windows
Where command is equal to which command in Unix/linux. This will onlyl works from windows 2003 version
where command prints the location of file for a given search pattern, This search given search pattern in environment variable path .
Here is an syntax
where [options] searchpattern
/R - recursive path for searching files /F - displays the files path in double quotes /T - Displays file path metadata like size,modified date
It contains string or pattern of string using * for multiple, ? for single character
Here is an help documentation for where.exe command
Here is an example where command for location of 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 word that starts with
jav, suffix * to it
if you used search pattern jav?, It searchs for words
jav or and fourth letter might be any single letter or zero.
window powershell which alternative
Get-Command in powershell works same as where command, This will works 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 runtime tool that supports linux commands in windows.
you can install from here
all the linux commands works in windows, which command also works as expected
To sumup, Where command in DOS of windows and Get-Command in powershell are the alteratives to which command in windows.