Windows的PowerShell新增which命令

发现在PowerShell找命令的路径时,发现没有which命令,只能使用Get-Command或where.exe来查找命令的路径,喜欢Linux命令的简捷性,想在PowerShell中也能直接使用which命令。


打开PowerShell配置文件

1
2
# 编辑配置文件
notepad $PROFILE

在打开的记事本中添加以下内容并保存:

1
Set-Alias which Get-Command

重新打开 PowerShell 后,which 命令就可以直接使用了。

测试查询Python路径

1
which python

结果

1
2
3
CommandType     Name        Version    Source
----------- ---- ------- ------
Application python.exe 3.11.0 D:\miniconda3\python.exe

拓展查询其他命令路径

用于查询目录下的所有文件和子目录

1
Set-Alias ll Get-ChildItem -Force

Windows的PowerShell新增which命令
http://pygo2.top/articles/10392/
作者
mingliang.gao
发布于
2026年7月28日
许可协议