加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – PowerShell相当于BASH(etc)’type’命令?

发布时间:2020-12-14 01:47:17 所属栏目:Windows 来源:网络整理
导读:在* nix上,使用BASH(等)通过使用内置的’type’ shell,询问系统命令所在的位置(等): $type catcat is /bin/cat Microsoft PowerShell 2.0中是否存在等效的“类型”命令? 相当于Get-Command. PS C: Get-Command lsCommandType Name Definition-----------
在* 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:usrlocalwbinls.exe
Application     ls.exe     C:Program Files (x86)Gitbinls.exe

Windows 10更新:

由于我发布了这个答案,看来Get-Command的行为已经改变了.要包含所有结果(以Un * x的样式),现在我需要传递-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)Gitusrbinls.exe

如评论中所述,这不包括“定义”列,就像之前的行为一样.我无法确定添加定义列的命令行参数,但正如@voutasaurus在下面的注释中所指出的,可以使用:

PS C:&; (Get-Command -All ls).Definition
Get-ChildItem
C:Program Files (x86)Gitusrbinls.exe

版本信息供参考(我没有与原始答案文本相关的版本信息,但我猜它是Windows 7):

PS C:&; [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      15063  0

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读