--- layout: page category-title: Basic commands category-page: basic tags: directory list author: Alessandro Marinelli title: mkdir previous-page: pages/cmd/basic/cd.html ---

The mkdir command is used to create new directories
The name stands for MaKe DIRectory.

Syntax

The default ls command syntax is:

mkdir [flags] [-m mode] directory_name ...
Where [flags] are the mkdir -p and -v - flags, read below for more info,and directory_name is the name of the new directory we are going to create.

Usage


Create a new directory

Let's see how to create a new directory

 Device-Name:test YourName$ mkdir test_directory
 Device-Name:test YourName$ ls
test_directory

Now we have created a new directory defined by the relative path test/test_directory . Let's use the command ls to see if the experiment succeded.

    Device-Name:test YourName$ ls
   test_directory
 

As you can see, the directory test_directory has been created inside the directory test

Create a Path of directories

Using the flag -p we can create a path of directories, allowing us to build more than a directory at once.

Device-Name:test lexinde$ mkdir -p test_directory/test_-pflag/A_Dir_in_a_Dir
  

As you can see, we are now creating two directories: one named test_-pflag and another one, included in this, named A_Dir_in_a_Dir

Notice:the -p flag is necessary to allow the shell to create intermidiate directories as required

Create directories with specified permissions

The -m mode option allows us to set permissions at the new directory that we are now creating.
Device-Name:test YourName$ mkdir -m 777 test_free_directory

Our new directory will now have read,write and execute permissions for user, group and ...,. Go to chmod to see more infos about permissions.