由于我有时遇到路径问题,其中一个我自己的 cmd 脚本被另一个程序隐藏(阴影)(在路径的前面),我希望能够在 Windows 命令行上找到程序的完整路径,给定只是它的名字。
有没有相当于 UNIX 命令 '哪个'?
在 UNIX 上, which command打印给定命令的完整路径,以便轻松查找和修复这些阴影问题。 
 Windows Server 2003 和更高版本(如 Windows XP 32 位之后的任何东西)提供where.exe程序,做什么一些which呢,虽然它匹配所有类型的文件,而不只是执行命令。 (它与cd类的内置 shell 命令不匹配。)它甚至会接受通配符,因此where nt*查找%PATH%和当前目录中名称以nt开头的所有文件。 
试试where /?求助。 
请注意,Windows PowerShell 将Where-Object cmdlet的别名定义where Where-Object ,因此如果您需要where.exe ,则需要键入全名而不是省略.exe扩展名。 
虽然 Windows 的更高版本具有where命令,但您也可以使用环境变量修饰符在 Windows XP 中执行此操作,如下所示: 
c:\> for %i in (cmd.exe) do @echo.   %~$PATH:i
   C:\WINDOWS\system32\cmd.exe
c:\> for %i in (python.exe) do @echo.   %~$PATH:i
   C:\Python25\python.exe您不需要任何额外的工具,它不仅限于PATH因为您可以替换您希望使用的任何环境变量(当然是路径格式)。 
并且,如果你想要一个可以处理 PATHEXT 中的所有扩展的东西(就像 Windows 本身那样),这个就可以了:
@echo off
setlocal enableextensions enabledelayedexpansion
:: Needs an argument.
if "x%1"=="x" (
    echo Usage: which ^<progName^>
    goto :end
)
:: First try the unadorned filenmame.
set fullspec=
call :find_it %1
:: Then try all adorned filenames in order.
set mypathext=!pathext!
:loop1
    :: Stop if found or out of extensions.
    if "x!mypathext!"=="x" goto :loop1end
    :: Get the next extension and try it.
    for /f "delims=;" %%j in ("!mypathext!") do set myext=%%j
    call :find_it %1!myext!
:: Remove the extension (not overly efficient but it works).
:loop2
    if not "x!myext!"=="x" (
        set myext=!myext:~1!
        set mypathext=!mypathext:~1!
        goto :loop2
    )
    if not "x!mypathext!"=="x" set mypathext=!mypathext:~1!
    goto :loop1
:loop1end
:end
endlocal
goto :eof
:: Function to find and print a file in the path.
:find_it
    for %%i in (%1) do set fullspec=%%~$PATH:i
    if not "x!fullspec!"=="x" @echo.   !fullspec!
    goto :eof它实际上返回了所有可能性,但您可以轻松地针对特定搜索规则进行调整。
在 PowerShell 下, get-command将在$Env:PATH任何位置找到可执行文件。 
get-command eventvwr
CommandType   Name          Definition
-----------   ----          ----------
Application   eventvwr.exe  c:\windows\system32\eventvwr.exe
Application   eventvwr.msc  c:\windows\system32\eventvwr.msc它还发现 PowerShell 命令,函数,别名文件通过自定义的可执行文件的扩展$Env:PATHEXT等为当前 shell(非常类似于 bash 的定义type -a foo ) - 使其成为一个更好的走向不是像其他工具where.exe , which.exe等不知道这些 PowerShell 命令。 
你可以快速设置一个带有sal which gcm的别名sal which gcm ( set-alias which get-command的set-alias which get-command缩写形式)。