130 windows powershell command-line which
在 Linux 中,我们有“which”命令来找出可执行文件的路径。
它的 Windows 等价物是什么?是否有任何 PowerShell 命令可以执行此操作?
Ran*_*evy 129
较新版本的 Windows(我认为 Windows 2003 及更高版本)具有 where 命令:
C:\>where ping
C:\Windows\System32\PING.EXE
Run Code Online (Sandbox Code Playgroud)
对于 PowerShell,显式添加 .exe 后缀:
PS C:\>where.exe ping
C:\Windows\System32\PING.EXE
Run Code Online (Sandbox Code Playgroud)
小智 57
是的,Get-Command会找到包括可执行文件在内的所有命令:
PS\> Get-Command ipconfig
Run Code Online (Sandbox Code Playgroud)
如果要将命令限制为可执行文件:
PS\> Get-Command -CommandType Application
Run Code Online (Sandbox Code Playgroud)
会在你的路径中找到所有的exes。有一个交互使用的别名:
PS\> gcm net* -CommandType Application
Run Code Online (Sandbox Code Playgroud)
要获取可执行文件的路径,您可以使用Path返回对象的属性。例如:
PS\> (Get-Command notepad.exe).Path
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请运行man Get-Command -full。
where.exe明确而不是where在 PowerShell 中为我工作:
PS C:\Users\birdc> where ping
PS C:\Users\birdc> where.exe ping
C:\Windows\System32\PING.EXE
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
70223 次 |
| 最近记录: |