相当于linux“mkdir -p"的powershell? [英] powershell equivalent of linux "mkdir -p"?
问题描述
如何让 powershell "mkdir" 命令像 Linux 的 mkdir -p
命令一样工作?
How can I get the powershell "mkdir" command to act exactly like Linux's mkdir -p
command?
在 Linux 下,mkdir -p
将创建嵌套目录,但前提是它们不存在.例如,假设您有一个目录 /foo
,您对其具有写入权限.mkdir -p/foo/bar/baz
在现有 /foo
下的 bar 内创建 bar 和 baz.再次运行相同的命令,不会出错,但不会创建任何内容.
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.
推荐答案
您可以使用 -ErrorAction SilentlyContinue
参数忽略 PowerShell 中的错误(您可以将其缩短为 -ea 0代码>).完整的 PowerShell 命令是
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
您可以将其缩短为
md /foo/bar/baz -ea 0
(如果您愿意,也可以键入 mkdir
而不是 md
.)
(You can also type mkdir
instead of md
if you prefer.)
请注意,当使用 New-Item -ItemType Directory
(或 md
或 mkdir
别名).如果你不想要任何输出,你可以通过管道传送到 Out-Null
.
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
.
这篇关于相当于linux“mkdir -p"的powershell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!