Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the PowerShell Verb-Noun definition for the mkdir alias?

Tags:

powershell

In Windows PowerShell, the alias md relates to the definition mkdir, which also seems to be an alias (i.e. not a Verb-Noun definition.) as this command indicates:

: get-item -path alias:* | where-object {$_.Definition -eq "mkdir"}

CommandType     Name
-----------     ----
Alias           md -> mkdir
like image 718
intrepidis Avatar asked Apr 01 '18 11:04

intrepidis


People also ask

What is PowerShell alias?

An alias is an alternate name for a cmdlet, function, executable file, including scripts. PowerShell includes a set of built-in aliases. You can add your own aliases to the current session and to your PowerShell profile. The Alias drive is a flat namespace that contains only the alias objects.

What does mkdir do in PowerShell?

Creates a directory or subdirectory. Command extensions, which are enabled by default, allow you to use a single mkdir command to create intermediate directories in a specified path. This command is the same as the md command.

How do I delete an alias in PowerShell?

The Remove-Alias cmdlet removes an alias from the current PowerShell session. To remove an alias with the Option property set to ReadOnly, use the Force parameter. The Remove-Alias cmdlet was introduced in PowerShell 6.0.


1 Answers

PowerShell's Get-Command cmdlet allows you to reflect on command names:

PS> Get-Command md

CommandType     Name                                               Version    Source                 
-----------     ----                                               -------    ------                 
Alias           md -> mkdir                                                                          

This tells you that md is an alias and that it resolved to a command named mkdir.

PS> Get-Command mkdir

CommandType     Name                                               Version    Source                 
-----------     ----                                               -------    ------                 
Function        mkdir                                                                                

This tells you that mkdir is a function.

To see that function's definition (function body), access the .Definition property on the object returned by Get-Command:

(Get-Command mkdir).Definition # outputs the function's body

The output of the above will tell you that mkdir is a proxy function for New-Item -ItemType Directory.
In other words: it provides a file-system-specific shortcut for creating directories to the more generic New-Item cmdlet - see Get-Help about_Providers to learn about PowerShell's generalization of the concept of drives.

like image 153
mklement0 Avatar answered Dec 05 '22 21:12

mklement0