On *nix, using BASH (etc) you ask the system where a command is located (etc) by using the 'type' shell built-in like this:
$ type cat
cat is /bin/cat
Is there an equivalent of this 'type' command in Microsoft PowerShell 2.0 ?
An equivalent is 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've posted this answer, it appears that the behavior of Get-Command
has changed. To include all results (in the style of Un*x) type
), now I need to pass the -All
flag, like so:
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 a comment, this doesn't include the Definition
column as was the previous behavior. I can't determine a command-line argument to add the definition column, but as noted by @voutasaurus in the comment below, one 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 odn't have the version information associated with the original answer text, but I'm guessing that it was Windows 7):
PS C:\> [System.Environment]::OSVersion.Version
Major Minor Build Revision
----- ----- ----- --------
10 0 15063 0
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