Windows与Unix中的“哪个”命令等效吗?有等效的PowerShell命令吗?


Answers:


79

Windows的某些版本(我认为Windows 2003及更高版本)具有where命令:

c:\>where ping
C:\Windows\System32\PING.EXE

5
where在Windows 7中为我工作
— Nam G VU

6
这仅适用于cmd,不适用于PowerShell(以我的经验)
— Thomas

where /r c:\ fileName添加/ RC:\让我来执行递归搜索开始使用Windows 7专业版,似乎不会在C盘的根目录access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/...
— CrandellWS

6
在Powershell中,您应该说,where.exe ping因为where默认情况下别名为Where-Objectcmdlet,而这是完全不同的故事
— maoizm

where.exewhere在PowerShell中为我明确而不是为我工作
— drkvogel

36

是的,Get-Command将找到所有命令,包括可执行文件:

PS\> Get-Command ipconfig

如果要将命令限制为仅可执行文件:

PS\> Get-Command -CommandType Application

将找到您路径中的所有exe。有一个用于交互式使用的别名:

PS\> gcm net* -CommandType Application

要获取可执行文件的路径,可以使用Path返回对象的属性。例如:

PS\> (Get-Command notepad.exe).Path

有关更多信息,请运行man Get-Command -full。


2

除了user10404之外,help命令还将对别名起作用,因此您可以使用相同的命令名称(gcm)进行帮助和交互使用:

help gcm -Parameter *
# or
man gcm -Par *

2

如果要简短,请创建一个内容为一行的which.cmd文件

echo %~$PATH:1

这将搜索提供给脚本的第一个参数(%1),并显示找到的文件的完整路径。将此脚本放在Windows 10中的好地方是%LOCALAPPDATA%\ Microsoft \ WindowsApps \ which.cmd

然后您在路径中获得了哪个命令。

c:\>which cmd.exe

c:\>echo C:\Windows\System32\cmd.exe
C:\Windows\System32\cmd.exe

1

where.exe而不是where在PowerShell中为我工作:

PS C:\Users\birdc> where ping
PS C:\Users\birdc> where.exe ping
C:\Windows\System32\PING.EXE

在Windows 10 1903年的作品
— Ultrasonic54321

在PowerShell中?我使用的是Windows 10 Pro 1903,where ping在PowerShell中没有任何帮助。
— drkvogel

对不起,我不清楚。我是说where.exe。
— Ultrasonic54321
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.