在* nix上,使用BASH(等)通过使用内置的'type'shell,询问系统命令所在的位置(等):
$ type cat
cat is /bin/cat
Microsoft PowerShell 2.0中是否存在等效的“类型”命令?
相当于Get-Command
。
PS C:\> Get-Command ls
CommandType Name Definition
----------- ---- ----------
Alias ls Get-ChildItem
Application ls.exe D:\usr\local\wbin\ls.exe
Application ls.exe C:\Program Files (x86)\Git\bin\ls.exe
Windows 10更新:
自从我发布了这个答案后,Get-Command
的行为似乎发生了变化。要包含所有结果(以Un * x的风格)type
),现在我需要传递-All
标志,如下所示:
PS C:\> Get-Command -All ls
CommandType Name Version Source
----------- ---- ------- ------
Alias ls -> Get-ChildItem
Application ls.exe 0.0.0.0 C:\Program Files (x86)\Git\usr\bin\ls.exe
如评论中所述,这不包括Definition
列,就像之前的行为一样。我无法确定添加定义列的命令行参数,但正如@voutasaurus在下面的注释中所指出的,可以使用:
PS C:\> (Get-Command -All ls).Definition
Get-ChildItem
C:\Program Files (x86)\Git\usr\bin\ls.exe
版本信息供参考(我没有与原始答案文本相关的版本信息,但我猜它是Windows 7):
PS C:\> [System.Environment]::OSVersion.Version
Major Minor Build Revision
----- ----- ----- --------
10 0 15063 0
既然你用Shell标记了这个,那么除了PowerShell的Get-Command
之外,还有where.exe
:
PS C:\> where.exe notepad
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe
该命令只是通过路径查找具有指定名称的文件:
PS C:\> where.exe readme.*
C:\Python31\README.txt
C:\Program Files (x86)\wget\README
C:\Program Files (x86)\SysinternalsSuite\readme.txt
请注意,从PowerShell调用此命令时,必须将其命名为where.exe
,因为Where-Object
是where
的别名。