{

Where command in windows | which command alternatives


where command windows examples

In Linux, 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

options:-

/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

searchpattern:

It contains string or pattern of string using * for multiple, ? for a single character

Here is help documentation for the where.exe command
C:\>where /?

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

where jav*

if you used search pattern jav?, It searches for words jav or and fourth letter might be any single letter or zero.

where jav?

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 tool

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

Conclusion

To sum up, Where command in DOS of windows and Get-Command in PowerShell are the alternatives to which command in windows.

THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.