167
33
Is there an equivalent of the Unix whereis command in Windows?
So that I could figure out where commands I can run actually is.
167
33
Is there an equivalent of the Unix whereis command in Windows?
So that I could figure out where commands I can run actually is.
211
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
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)
)
1This is a good fix for older systems, but you should know that it results in a few quirks. It matches directories, only returns the first result found in the path for each extension, and should include every extension found in the PATHEXT environment variable. – Kevin – 2009-09-11T14:48:01.630
yah, this is a bit older hack of mine, when i pasted it here i instantly saw the potential for %PATHEXT% :) – akira – 2009-09-11T18:08:45.627
7
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
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.
2
There is at least a Windows port for the which
utility.
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
0
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
I'm not proficient in powershell but it seems you're searching through the whole directory tree. This is not equivalent to where
which only searches in the %PATH%
. Moreover it's much slower and gives errors for folders you don't have read permission – phuclv – 2017-04-30T03:07:09.000
Agreed... I did not require an exact copy of the functionality, just the ability to locate a program. – KalenGi – 2017-04-30T09:44:44.253
-1
You can try searching for the command using the following:
dir /s type-whatever-you-are-searching
This does not work for me. For example, the exp command is in my path, but dir/s exp or dir /s exp.exe just gives "File Not Found". – bobmcn – 2009-09-10T21:12:12.687
5This would work if a) you search from the root of the drive, b) your path is all on one drive, and c) your path is in lexicographical order. Even under these conditions it will be ridiculously slow. – Kevin – 2009-09-10T23:09:35.727
4Everyday I learn something new... – Rubens Mariuzzo – 2013-01-25T04:00:25.793
4Kind of sad
where
just returns usage help now in Windows 7. Wanted to see it for myself :p – Svish – 2014-02-06T13:48:07.4272
where
not available in XP – Tom Roggero – 2014-02-10T01:55:18.7271@TomRoggero, I could have been more clear. It's part of the optional resource kit starting with Windows 98, and only included in the base install for version after XP. – Kevin – 2014-02-10T17:32:25.300