Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows / Powershell version of the Unix 'which' Utility [duplicate]

The 'which' utility, when run with a parameter naming an executable, will tell you the first executable with that name it finds in your path, if found at all. This gives a good idea which version of the executable will be run. (Forgive me if this description is incomplete, but it conveys the general idea)

I'm looking for either a port of the 'which' utility, a Powershell command, or some other utility I'm not aware of that does the same thing.

I have looked at the following SO question (and will try the for loop logic in the selected answer). I'd prefer to have a single command that implements this functionality and want to see if that exists. If something like that doesn't exist, that logic would be fairly easily put into a script:

unix "which java" equivalent command on windows?


The "winwhich" utility on CodeProject exists. It hasn't been updated in 6 years or so and, when built on my Win 7 machine with VS 2010, crashed upon running. I plan to do my due diligence to find out why it crashed, but don't have time until tonight.


Has anybody used another utility or command on Windows to emulate this functionality?

like image 968
Taylor Price Avatar asked Dec 19 '11 19:12

Taylor Price


People also ask

Is PowerShell the same as Unix?

PowerShell is superficially similar to Unix shells. PowerShell has aliases for many of the commands you are used to in Unix, like ls, rm, cp, mv, etc. However, the way that the cmdlets behind the aliases work is quite different.

Does PowerShell use Unix?

There is no Unix-style job-control support in PowerShell on Linux or macOS. The fg and bg commands are not available. You can use PowerShell jobs that do work across all platforms. Putting & at the end of a pipeline causes the pipeline to be run as a PowerShell job.

What is the PowerShell equivalent of cat?

What is cat equivalent command in windows? The type command is a Windows cat equivalent that works on command-line prompt and a Windows PowerShell.


3 Answers

You can use Get-Command <command>, or shorten it to gcm.

like image 155
Novakov Avatar answered Nov 09 '22 19:11

Novakov


where does the same on recent versions of Windows. If you're after a PowerShell command, Novakov's answer is correct.

like image 38
Joey Avatar answered Nov 09 '22 21:11

Joey


On Windows from Command Prompt (cmd)

cmd> where <command>

In Powershell (PS)

ps> get-command <command>
ps> where.exe <command>

You can also add alias to the 'which' command in PS

ps> New-Alias which get-command

and now you can use 'which' command like usual

ps> which <command>
like image 26
Vlad Bezden Avatar answered Nov 09 '22 20:11

Vlad Bezden