Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between mkdir and mkdir -p?

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.

like image 531
Robert Holman Avatar asked Oct 22 '12 19:10

Robert Holman


People also ask

What is the mkdir P?

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.

What's the difference between mkdir and touch?

We use touch to create plain files, we use mkdir to create directories. This is the difference.

What is the meaning of mkdir?

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.

What does mkdir ~/ do?

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).


1 Answers

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
like image 182
EBGreen Avatar answered Oct 04 '22 08:10

EBGreen