β

Windows中查找命令的路径 (类似Linux中的which命令)

lenglingx的个人页面 532 阅读

Linux有个Which命令,用来查找可执行文件的位置。

例如:which find, 就会从PATH变量的路径里搜索该命令,返回找到的第一个匹配的结果。

这样我们就可以知道,我们用的find程序是哪里的。

Windows没有这样的指令,我们可以自己写一个:

@echo off
echo %~dp$PATH:1
@echo on

其它的方法:


1.where is a direct equivalent:
C:\Users\Joey>where cmd
C:\Windows\System32\cmd.exe

Note that in PowerShell where itself is an alias for Where-Object, thus you need to usewhere.exe in PowerShell.


2.In cmd you can also use for:
C:\Users\Joey>for %x in (powershell.exe) do @echo %~$PATH:x
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe


3.In PowerShell you have Get-Command and its alias gcm which does the same if you pass an argument (but also works for aliases, cmdlets and functions in PowerShell):
PS C:\Users\Joey> Get-Command where

CommandType     Name          Definition
-----------     ----          ----------
Alias           where         Where-Object
Application     where.exe     C:\Windows\system32\where.exe

The first returned command is the one that would be executed.

转自网络。

作者:lenglingx的个人页面
独钓渔的博客

发表评论