In Linux systems, you can create new directories either from the command line or with the help of your desktop’s file manager. The command that allows you to create directories (also known as folders) is mkdir.

This tutorial covers the basics of using the mkdir command, including everyday examples.

Linux mkdir Command Syntax

The syntax for the mkdir command is as follows:


The command takes one or more directory names as its arguments.

How to Create a New Directory

To create a directory in Linux pass the name of the directory as the argument to the mkdir command. For example, to create a new directory newdir you would run the following command:

mkdir newdir

You can verify that the directory was created by listing the contents using the [ls]( command :

ls -l
drwxrwxr-x 2 username username 4096 Jan 20 03:39 newdir

When providing only the directory name, without the full path, it is created in the current working directory.

The current working directory is the directory from which you are running the commands. To change the current working directory, use the [cd]( command.

To create a directory in another location you’ll need to provide the absolute or relative file path to the parent directory. For example, to create a new directory in the /tmp directory you would type:

mkdir /tmp/newdir

If you try to create a directory in a parent directory where the user does not have sufficient permissions you will receive Permission denied error:

mkdir /root/newdir
mkdir: cannot create directory '/root/newdir': Permission denied

The -v (--verbose) option tells mkdir to print a message for each created directory.

How to Create Parent Directories

A parent directory is a directory that is above another directory in the directory tree. To create parent directories, use the -p option.

Let’s say you want to create a directory /home/linuxize/Music/Rock/Gothic:

mkdir /home/linuxize/Music/Rock/Gothic

If any of the parent directories don’t exist you will get an error as shown below:

mkdir: cannot create directory '/home/linuxize/Music/Rock/Gothic': No such file or directory

Instead of creating the missing parent directories one by one, invoke the mkdir command with the -p option:

mkdir -p /home/linuxize/Music/Rock/Gothic

When the -p option is used, the command creates the directory only if it doesn’t exist.

If you try to create a directory that already exists and the -p option is not provided, mkdir will print File exists error:

mkdir newdir
mkdir: cannot create directory 'newdir': File exists


How to Create Directories in Linux (mkdir Command)
1.40 GEEK