What is the mkdir Linux command?

Linux is an open-source operating system that is similar to Unix-based operating systems such as MacOS. It provides a command line, essentially a graphical user interface for system users to enter shell commands they want to execute on the system. One of these commands is the mkdir command.

The mkdir command

The mkdir command creates a new folder in the system as the command's name comes from the words "make directory."

Syntax

Below, we can see the syntax for the command.

mkdir [OPTION] folderName

The folderName represents a placeholder where we must enter the name of the folder we want to create.

If we want to create a folder named myFolder, we'll use the following command:

mkdir myFolder

We can also add the command parameters in place of OPTION shown in the syntax above.

Command parameters

The table below shows the different parameters we can use alongside the command.

Parameter Types

Parameter

Description

--mode or -m

Sets the file permissions at the time of creation.

--parents or -p

Makes the parent directories if they do not already exist.

--verbose or -v

Displays a message for each file created.

-Z = context or --context = context

In a SELinux-enabled kernel, this option sets the security context of each created directory to the specified context.

--version

Displays the version.

--help

Opens the command's manual.

Below, we can see examples of the parameters mentioned in the table above.

--mode parameter

If we want to create a directory myFolder with all permissions of users and no permissions for groups and others, we will use the command:

mkdir --mode 0700 myFolder

--parents parameter

If we want to create a directory etc/user/folder but the folder etc and user do not exist, we can use the parents argument to create these folders as shown below.

mkdir --parents etc/user/folder

--verbose parameter

If we want to display a message, the created directory myFile created, we can use the following command:

mkdir --verbose myFile

-Z parameter

Let's suppose we are making a folder newFolder and we want it to have the default SELinux security context; we can use the command:

mkdir -Z newFolder

--version parameter

If we want to display the version information for the command, we can execute the following command:

mkdir --version

--help parameter

To open the manual of the mkdir command we can use the following command.

mkdir --help

Practice exercise

Below, we can see a terminal in which we can use the mkdir command and pass the above parameters to the command to see how they work.

Terminal 1
Terminal
Loading...

Quiz

Now that we have gone through what is the mkdir command and its parameters, let's try to solve the quiz attached below.

1

What does mkdir stand for?

A)

Make Directory

B)

Move Directory

C)

Main Directory

Question 1 of 40 attempted

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved