Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell equivalent of linux "mkdir -p"?

Tags:

powershell

How can I get the powershell "mkdir" command to act exactly like Linux's mkdir -p command?

Under Linux, mkdir -p will create nested directories, but only if they don't exist already. For example, suppose you have a directory /foo that you have write permissions for. mkdir -p /foo/bar/baz creates bar and baz within bar under existing /foo. You run the same command over again, you will not get an error, but nothing will be created.

like image 458
Bimo Avatar asked Nov 17 '17 18:11

Bimo


People also ask

What is mkdir P in Windows?

The mkdir (make directory) command in the Unix, DOS, DR FlexOS, IBM OS/2, Microsoft Windows, and ReactOS operating systems is used to make a new directory. It is also available in the EFI shell and in the PHP scripting language. In DOS, OS/2, Windows and ReactOS, the command is often abbreviated to md . mkdir.

What is mkdir p option?

Linux Directories mkdir -p With the help of mkdir -p command you can create sub-directories of a directory. 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.

What does mkdir p mean in Linux?

mkdir -p means: create the directory and, if required, all parent directories. The fact that this makes little sense when the path is specified as . , so the current working directory, does not change this. Most likely the line where the path is defined is meant to be adapted as required.

What is the difference between mkdir and mkdir with P?

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.


1 Answers

You can ignore errors in PowerShell with the -ErrorAction SilentlyContinue parameter (you can shorten this to -ea 0). The full PowerShell command is

New-Item /foo/bar/baz -ItemType Directory -ea 0

You can shorten this to

md /foo/bar/baz -ea 0

(You can also type mkdir instead of md if you prefer.)

Note that PowerShell will output the DirectoryInfo object it creates when using New-Item -ItemType Directory (or the md or mkdir aliases). If you don't want any output, you can pipe to Out-Null.

like image 103
Bill_Stewart Avatar answered Oct 20 '22 05:10

Bill_Stewart