I’ve been following Learn Code the Hard Way’s tutorial on learning how to utilize the command line interface in PowerShell. In this article, it tells me to use the command mkdir -p i\like\icecream. At the bottom, it explains “mkdir -p will make an entire path even if all the directories don’t exist.”
I’m confused, as mkdir i\like\icecream without the -p argument still does the same thing. I’ve experimented and done stuff such as creating a “one” directory, then creating “one\two\three” with mkdir and it will automatically create a two directory for three to be placed in. Does PowerShell automatically assume -p or something in cases like this? I’m at a loss as to what this argument does.
PowerShell does its best to determine what parameter you mean even if you don’t give it fully. Thus if you use the
-pparameter, you are actually using-path.For the mkdir function, the
-pathparameter tells the function the path to create.-pathis also by default the first argument to the function if no explicit parameters are provided. So calling the function with-p(-path) and without-pare exactly the same thing as far as the function is concerned.For more information, in the shell type:
I will also clarify that when you call mkdir, what you are really doing is calling the New-Item cmdlet and specifying the -ItemType parameter as Directory. That is why you see the New-Item help when you run that command. If you want to see the actual code for the mkdir function to see how it does this, do this: