Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the cmd/powershell equivalent of `which` on bash? [duplicate]

Tags:

powershell

cmd

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?

like image 442
bastibe Avatar asked Jun 13 '12 06:06

bastibe


People also ask

What is the equivalent of which in PowerShell?

In a Windows PowerShell the alternative for the which command is the Get-Command utility.

What is the difference between cmd PowerShell and Bash?

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.

Does PowerShell have Bash commands?

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.

What is the Bash equivalent in Windows?

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.


1 Answers

Various.

  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 use where.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.

like image 76
Joey Avatar answered Sep 25 '22 18:09

Joey