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.
Linux Directories mkdir -p It will create parent directory first, if it doesn't exist. But if it already exists, then it will not print an error message and will move further to create sub-directories. This command is most helpful in the case when you don't know whether a directory alredy exists or not.
We use touch to create plain files, we use mkdir to create directories. This is the difference.
The mkdir command in Linux/Unix allows users to create or make new directories. mkdir stands for “make directory.” With mkdir , you can also set permissions, create multiple directories (folders) at once, and much more.
mkdir() sets the access, change, modification, and creation times for the new directory. It also sets the change and modification times for the directory that contains the new directory (parent directory).
PowerShell does its best to determine what parameter you mean even if you don't give it fully. Thus if you use the -p
parameter, you are actually using -path
.
For the mkdir function, the -path
parameter tells the function the path to create. -path
is also by default the first argument to the function if no explicit parameters are provided. So calling the function with -p
(-path
) and without -p
are exactly the same thing as far as the function is concerned.
For more information, in the shell type:
Get-Help mkdir
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:
(get-command mkdir).ScriptBlock
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