254

Is there an equivalent of the Unix whereis command in Windows?

So that I could figure out where commands I can run actually is.

Svish
  • 41,258

11 Answers11

308

The where command does what you want and goes back at least to the resource kit for Windows 98, and is included by default in Server 2003, Vista, and newer:

C:\>where csc
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe
C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe

If executed with no arguments (on Vista), it results in one of my favorite messages:

C:\>where
ERROR: The operation completed successfully.

If executing in PowerShell, be sure to include '.exe' to distinguish from any 'where' aliases or scripts along the path. ('where' is a typical alias for Where-Object.ps1)

C:\> where.exe where.exe
C:\Windows\System32\where.exe
J Burnett
  • 143
Kevin
  • 4,011
  • 1
  • 19
  • 9
32

You can run the following PowerShell command:

gcm <command>

Get-Command

The Get-Command cmdlet gets all commands that are installed on the computer, including cmdlets, aliases, functions, filters, scripts, and applications. Get-Command gets the commands from PowerShell modules and commands that were imported from other sessions. To get only commands that have been imported into the current session, use the ListImported parameter.

Ramhound
  • 44,080
16

Please, use where command:

> where app.exe

It is the best way to achieve your goal.

You can also use PowerShell command:

> $env:path.Split(';') | gci -Filter app.exe

and expanded version looks like this:

 > $env:path.Split(';') | select -Unique | ? {$_ -and (test-path $_)} | gci -Filter app.exe
Arek Bee
  • 261
7

hackerish which.cmd:

@echo off
@set PATH=.;%PATH%

@rem 
@rem about:  something similar like the unix-alike-which, but with
@rem         within pure cmd
@rem 

if "%1" == "" (
    @echo Usage: 
    @echo.
    @echo   which 'cmd'
    @echo.
    @echo.if 'cmd' is not found, ERRORLEVEL is set to 1
    @echo.  
) else (
    ( @for %%f in (%1 %1.exe %1.cmd %1.bat %1.pif) do if not "%%~$PATH:f" == "" ( @echo %%~$PATH:f ) else @set ERRORLEVEL=1) 
)
akira
  • 63,447
3

Using the where command on windows 10, in cmd, I used the following command to recursively search c drive for copies of the c# compiler, csc.exe.

c:\> where /r c:\ csc.exe

Sample:

enter image description here

Matt
  • 444
3

Somewhere "out there" I found this batch file whereis.bat:

@for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT "%%~$PATH:i"=="" echo %%~$PATH:i

Update: maybe I found it here.

1
function find ($string) { 
   Get-ChildItem -Path 'c:\' -Recurse -Filter $string; 
}

function whereis ($string) { 
   $superpath = "$env:Path;C:\Program Files;C:\Program Files (x86)";
   (echo $superpath).Split(';') | Get-ChildItem -Recurse -Filter $string; 
}

Example:

PS >find Mozilla.admx

    Directory: C:\Windows\PolicyDefinitions                                                                                     

Mode                LastWriteTime         Length Name                                                                           
----                -------------         ------ ----                                                                           
-a----        1/27/2016  12:22 PM          37146 Mozilla.admx                                                                   

PS >whereis firefox.exe

    Directory: C:\Program Files\Mozilla Firefox                                                                                 

Mode                LastWriteTime         Length Name                                                                           
----                -------------         ------ ----                                                                           
-a----        9/21/2017   5:30 PM         477136 firefox.exe        
Rupert
  • 31
1

which.cmd

@echo off

if "%~1" equ "" ( echo usage: %~n0 [command] & exit /b 0 ) else where $Path:%1 2>nul || ( echo | set /p x=%~n0: no '%1' in & path )

doskey.exe

doskey which=where $1 2$Gnul

Usage:

> which.cmd git
C:\Program Files\Git\cmd\git.exe

> which.cmd foo which: no 'foo' in PATH=C:\Windows\system32;C:\Windows;C:\Win dows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0 ;C:\Windows\System32\OpenSSH;C:\Program Files\PowerShell\7;

sionta
  • 31
1

There is at least a Windows port for the which utility.

innaM
  • 10,412
1

I was searching for this today and since I'm on XP without the resource kit, I turned to powershell with the following command:

dir -path c:\ -filter ffmpeg.* -r
KalenGi
  • 147
-1

You can try searching for the command using the following:

dir /s type-whatever-you-are-searching
phuclv
  • 30,396
  • 15
  • 136
  • 260