问题

软件 >> Windows >> PowerShell
Questions in category: PowerShell (PowerShell).

[PowerShell] 使用 get-command 查询某个命令所在路径

Posted by haifeng on 2024-10-10 08:49:39 last update 2024-10-10 08:57:34 | Answers (0) | 收藏


 

where 命令在 PowerShell 中并不是不起作用, 而是必须要加后缀 .exe. 
 
PS C:\Users\haife> where mysql
PS C:\Users\haife> where.exe mysql
C:\Program Files\MySQL\MySQL Server 8.4\bin\mysql.exe
也可以使用 get-command 
 
PS C:\Users\haife> (get-command mysql.exe).Path
C:\Program Files\MySQL\MySQL Server 8.4\bin\mysql.exe

这里 Path 也可以改为 source

PS C:\Users\haife> (get-command mysql).source
C:\Program Files\MySQL\MySQL Server 8.4\bin\mysql.exe 

 

get-command 可以缩写为 gcm

 

PS C:\Users\haife> (gcm mysql).Path
C:\Program Files\MySQL\MySQL Server 8.4\bin\mysql.exe
 
 

参考

windows - Equivalent of cmd's "where" in powershell - Super User