I would like to find out which version of an executable the CMD shell uses. In any unix shell, I would use which
to find it.
Is there an equivalent command in one of the Windows shells?
In a Windows PowerShell the alternative for the which command is the Get-Command utility.
CMD is the command line for Microsoft Windows operating system, with command-based features. Powershell is a task-based command-line interface, specifically designed for system admins and is based on the . Net Framework. Bash is a command-line and scripting language for most Unix/Linux-based operating systems.
PowerShell is similar to Bash. Mostly commands which are used in bash can be used in PowerShell like 'rm', 'ls', 'cp'. Both the shell include commands for managing files, navigating directories, and launching other programs.
Bash on Windows is a new feature added to Windows 10. Microsoft has teamed up with Canonical, aka the creators of Ubuntu Linux, to build this new infrastructure within Windows called the Windows Subsystem for Linux (WSL). It allows developers to access a complete set of Ubuntu CLI and utilities.
Various.
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 use where.exe
in PowerShell.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With