PowerShell equivalent of the BASH (etc) 'type' command?

In * nix, using BASH (etc.), you ask the system where the command is located (etc.), using the built-in shell like "type":

$ type cat cat is /bin/cat 

Is there an equivalent of this type command in Microsoft PowerShell 2.0?

+6
source share
2 answers

Equivalent to Get-Command .

 PS C:\> Get-Command ls CommandType Name Definition ----------- ---- ---------- Alias ls Get-ChildItem Application ls.exe D:\usr\local\wbin\ls.exe Application ls.exe C:\Program Files (x86)\Git\bin\ls.exe 

Windows 10 update:

Since I posted this answer, it seems that the behavior of Get-Command has changed. To include all the results (in Un * x style) type ), now I need to pass the -All flag, for example:

 PS C:\> Get-Command -All ls CommandType Name Version Source ----------- ---- ------- ------ Alias ls -> Get-ChildItem Application ls.exe 0.0.0.0 C:\Program Files (x86)\Git\usr\bin\ls.exe 

As noted in the comment, this does not include the Definition column, like the previous behavior. I cannot define a command line argument to add a definition column, but as @voutasaurus noted in the comment below, you can use:

 PS C:\> (Get-Command -All ls).Definition Get-ChildItem C:\Program Files (x86)\Git\usr\bin\ls.exe 

Version information for reference (I don't have version information related to the source of the response, but I assume it was Windows 7):

 PS C:\> [System.Environment]::OSVersion.Version Major Minor Build Revision ----- ----- ----- -------- 10 0 15063 0 
+7
source

Since you noted this with Shell, in addition to PowerShell Get-Command , there where.exe :

 PS C:\> where.exe notepad C:\Windows\System32\notepad.exe C:\Windows\notepad.exe 

The command simply looks for the file with the specified name along the path:

 PS C:\> where.exe readme.* C:\Python31\README.txt C:\Program Files (x86)\wget\README C:\Program Files (x86)\SysinternalsSuite\readme.txt 

Note that when invoking this command from PowerShell, you must name it as where.exe , because Where-Object has the alias where .

+1
source

Source: https://habr.com/ru/post/924863/


All Articles