PowerShell Equivalent of Linux mkdir Command
-
Use the
mkdir
Function as PowerShell Equivalent of the Linuxmkdir
Command -
Use
New-Item
as PowerShell Equivalent of the Linuxmkdir
Command
As we know, mkdir
is a popular command in Linux to create a directory in the system. In Windows, the File Explorer tool makes it easy to create files and folders.
You might need to create a new directory from Command Prompt or PowerShell when working on Windows. This tutorial will introduce different PowerShell commands equivalent to the Linux mkdir
command.
Use the mkdir
Function as PowerShell Equivalent of the Linux mkdir
Command
mkdir
is also available in Windows but as a function. It uses the New-Item
cmdlet to create a directory.
An empty folder will be created in the specified location. If no paths are given, it default creates a directory in the current working directory.
The following command creates a new folder, Test
, in the current working directory.
mkdir Test
Output:
Directory: C:\Users\rhntm
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 5/10/2022 7:06 PM Test
To make a new directory in a different location, you must specify the directory path. To specify a new directory path, you can use the -p
or -Path
parameter.
This command creates a directory at path C:\New\Record
.
mkdir -p C:\New\Record
Output:
Directory: C:\New
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 5/11/2022 8:07 AM Record
Use New-Item
as PowerShell Equivalent of the Linux mkdir
Command
You can use the New-Item
cmdlet to create files and folders in the file system. The primary use of this cmdlet is to create a new item and set its value.
This command creates a directory named Documents
in the C:
drive.
New-Item -Path "C:\Documents" -ItemType Directory
Output:
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 5/11/2022 10:12 AM Documents
The -Force
parameter can create a directory even if the specified name already exists on the location.
New-Item -Path "C:\Documents" -ItemType Directory -Force
Output:
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 5/11/2022 10:12 AM Documents