Javatpoint Logo
Javatpoint Logo

mkdir Command in Linux/Unix with Examples

Introduction to mkdir

Now let's learn how to create your own directory with the help of command prompt.

The mkdir stands for 'make directory'. With the help of mkdir command, you can create a new directory wherever you want in your system. Just type "mkdir <dir name> , in place of <dir name> type the name of new directory, you want to create and then press enter.

In ReactOS, Microsoft Windows, IBM OS/2, DR FlexOS, DOS, and Unix operating systems, the mkdir command is used to create a new directory. Also, it is available in the PHP scripting language and EFI shell. Often, the command is called md in ReactOS, Windows, OS/2, and DOS.

The command is related to the create_dir Stratus OpenVOS command. AmigaDOS and MetaComCo TRIPOS offer the same MakeDir command to make new directories. Many numerical computing platforms, such as GNU Octave and MATLAB, contain the mkdir function with the same functionality.

We can make multiple directories by setting the directories using permissions with the mkdir command. We can't make directories without permission, and we might face the "permission denied" error. The directories that should be made are required to be named, so mkdir creates that particular directory when the directory doesn't exist upon that name. But if that name exists, the mkdir command will not make the directory.



Linux mkdir command 1

In above example, I am in /home/sssit directory. I have made a directory 'created' by passing command "mkdir created".

Now if i'll try to create a new file with the same file name 'created' that technically already exists, I'll get an error message.

Note: If you will not provide a path then by default your file will be created in your current directory only. If you want to create your directory some where else, then provide the path of your destination directory and your file will be created there.

To make multiple directories


Linux mkdir command 2

You can also create multiple directories simultaneously. Look the example above, we have created multiple directories 'file1 file2 file3' .

Mkdir Options

mkdir -p, -parentsAdd directory including its sub directory.
mkdir -v, -verbosePrint a message for each created directory.
mkdir -m -mode=MODESet access privilege.
-ZIt sets the SELinux security context of all created directories to their default type.
--context[=CTX]It works like the -Z option. If the CTX is mentioned, it sets the SMACK or SELinux security context to CTX.
--versionIt shows the version number and some details of the license and then exits.
--helpIt shows the help-related details and then exits.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA