91
11
In Linux, we have the "which" command to find out the path of an executable.
What is its Windows equivalent? Is there any PowerShell command for doing that?
91
11
In Linux, we have the "which" command to find out the path of an executable.
What is its Windows equivalent? Is there any PowerShell command for doing that?
91
Some versions of Windows (I think Windows 2003 and up) have the where command:
c:\>where ping
C:\Windows\System32\PING.EXE
8This only works in cmd, not in PowerShell (in my experience) – Thomas – 2014-10-13T15:15:14.047
where /r c:\ fileName
adding the /r c:\ allowed me to perform a recursive search starting at the root of the C drive using Windows 7 Professional it seems to not be in https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Step_by_Step_Guide/ap-doslinux.html – CrandellWS – 2015-09-25T09:09:14.253
8in Powershell you should say where.exe ping
because where
is by default aliased to Where-Object
cmdlet which is completely different story – maoizm – 2018-05-27T11:18:55.760
where.exe
explicitly rather than where
works for me in PowerShell – drkvogel – 2019-09-26T15:35:03.003
5where
work for me in Windows 7 – Nam G VU – 2011-10-10T16:30:44.637
40
Yes, Get-Command
will find all commands including executables:
PS\> Get-Command ipconfig
If you want to limit the commands to just executables:
PS\> Get-Command -CommandType Application
Will find all exes in your path. There is an alias for interactive use:
PS\> gcm net* -CommandType Application
To get the path of an executable, you can use the Path
property of the returned object. For example:
PS\> (Get-Command notepad.exe).Path
For more info, run man Get-Command -full
.
4
where.exe
explicitly rather than where
works for me in PowerShell:
PS C:\Users\birdc> where ping
PS C:\Users\birdc> where.exe ping
C:\Windows\System32\PING.EXE
Works on Windows 10 1903. – Ultrasonic54321 – 2019-09-26T15:41:53.990
In PowerShell? I'm on Windows 10 Pro 1903, and where ping
gives me nothing in PowerShell. – drkvogel – 2019-09-26T15:53:13.413
Sorry I was unclear. I meant where.exe
. – Ultrasonic54321 – 2019-09-26T16:21:51.990
2
If you want to make it short, create a one line which.cmd file with the content
echo %~$PATH:1
This will search the first parameter (%1) fed to the script and display the full path of found file. Good place to put this script in windows 10 is %LOCALAPPDATA%\Microsoft\WindowsApps\which.cmd
And you get your which command in path.
c:\>which cmd.exe
c:\>echo C:\Windows\System32\cmd.exe
C:\Windows\System32\cmd.exe
2
In addition to user10404, the help command will work on aliases, so you can use the same command name (gcm) for help and interactive use:
help gcm -Parameter *
# or
man gcm -Par *
See also http://stackoverflow.com/questions/304319/is-there-an-equivalent-of-which-on-the-windows-command-line
– ysap – 2015-05-08T10:17:30.703Is there an equivalent of 'which' on the Windows command line? – phuclv – 2016-05-04T04:21:18.653